[英]Running PHP frontend site with node.js page connecting both together
[英]Running both PHP and Node.js on Nginx(php extension file for PHP, html extension for node)
美好的一天,我希望在同一服务器上处理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页面中包含的节点javascript。 如何在同一服务器上处理php和html这两种文件?
这样行不通。
问题是:当您使用nginx
+ php
,当您按下localhost/filename.php
时, nginx
不会真正运行php filename.php
localhost/filename.php
。 有php-fpm和nginx向它发送请求。 然后, php-fpm
运行实际脚本,创建正确的$_SERVER
, $_GET
等。
在node
情况下,您没有任何node-fpm
服务。 Nginx不会运行node filename.html
。 您需要在提供HTTP连接的8080端口上设置真实节点进程,因为所有nginx
所做的就是按照您的指定“传递”到http://localhost:8080
的实际http连接。
了解如何使节点http服务器正常工作。
PS提示:经常查看您的nginx日志(在Ubuntu / Debian中为/var/log/nginx/*
)。 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.