在Nginx上运行PHP和Node.js(PHP的PHP扩展文件,Node的html扩展文件)
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页面中包含的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/*
)。:)
相关文章:
- 将PHP mcrypt()调用转换为node's mcrypt
- 让node.js在pollingLoop中执行local.php文件
- node.js可以选择性地引入到用普通PHP/js/CSS/HTML构建的web应用程序中吗
- Node.js console.time()在PHP中等效
- PHP's SimpleXMLElement analog for Node.js
- 在PHP中查找Node和Golang这两个数组之间的差异
- Node.js对外部PHP aes-256-cbc进行解密,然后对其进行加密
- 如何从php或node.js获取websocket url路径
- 相当于node.js的var_dump(PHP)
- 在 PHP 中加密字符串,在 Node.js 中解密
- 与Node.js服务器和PHP服务器之间的差异之间的理论混淆
- 使用 Node Clone 重复 HTML/PHP 代码
- Node.js:从 PHP URL 下载(自动生成的)文件
- Node.js与传统PHP框架:如何结合
- Node.js + Socket.io 如何从 PHP 接收数据
- 如何在 Node.js 中使用我的 PHP 正则表达式
- node.js相当于标准的PHP ajax保存方案
- 将请求从node.js发送到PHP,返回一个数组
- 是否有一个 Node.js 相当于 PHP 的包含,以便包含的代码可以访问父文件的变量
- Expressjs/node.js相当于php中的exit()