0

Good day, i want handle php file and html on same server, i want that html files handle node on port 8080, and php files handle php5 service. I wrote nginx config like this:

server {
    listen 80 default_server;

    root /home/examle/public_html;
    index index.php index.html index.htm;

    server_name www.examle.com examle.com;

    location ~ \.html$ {
        proxy_pass http://localhost:8080;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    }

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

but when html pages opened nodejs didn't handle node javascript which contains in html page. How can i handle both type of files php and html on same server?

2
  • And what happens when you open sample.html ? 404 ? Commented Dec 2, 2015 at 5:32
  • page opened but node didn't handle javascript at all, if open example.com:8080/sample.html page displayed perfectly! Commented Dec 2, 2015 at 5:34

1 Answer 1

1

It won't work this way.

The thing is: when you use nginx+php, nginx doesn't really run php filename.php when you hit localhost/filename.php. There is php-fpm and nginx sends request to it. Then, php-fpm runs actual script, creating proper $_SERVER, $_GET, etc.

In node case, you don't have any node-fpm service. Nginx won't run node filename.html. You need to set up the real node process at 8080 port that serves http connections, because all nginx does is it "passes" an actual http connection to the http://localhost:8080, as you specified.

Learn how to get node http server working.

P.S. Clue: look at your nginx logs more often (/var/log/nginx/* at Ubuntu/Debian). :)

Sign up to request clarification or add additional context in comments.

1 Comment

Solved, solution you can find here: github.com/fastogt/siteonyourdevice/blob/master/node/… . Nginx work as needed but when starting load javascript sources cannot find it(i found it in browser debug mode "Reference io not defined") after that i specify where needed search javascript sources <script src="siteonyourdevice.com:3000/socket.io/socket.io.js"></…> and after that the page start loading in the right way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.