你好,我想在同一台服务器上处理php文件和html,我想让html文件处理8080端口上的节点,让php文件处理php5服务。我这样写nginx配置:
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;
}
}
但当html页面打开时,nodejs并没有处理html页面中包含的nodejavascript。如何在同一台服务器上处理php和html这两种类型的文件?
它不会以这种方式工作。
问题是:当您使用nginx
+php
时,当您达到localhost/filename.php
时,nginx
并不会真正运行php filename.php
。有php-fpm,nginx向它发送请求。然后,php-fpm
运行实际的脚本,创建合适的$_SERVER
、$_GET
等。
在node
的情况下,您没有任何node-fpm
服务。Nginx不会运行node filename.html
。您需要在为http连接提供服务的8080端口上设置真正的节点进程,因为nginx
所做的只是将实际的http连接"传递"给http://localhost:8080
,正如您所指定的那样。
了解如何使节点http服务器正常工作。
附言提示:经常查看nginx日志(Ubuntu/Debian上的/var/log/nginx/*
)。:)