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?
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.
PS Clue: look at your nginx logs more often ( /var/log/nginx/*
at Ubuntu/Debian). :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.