gpt4 book ai didi

javascript - 在 Nginx 上运行 PHP 和 Node.js(PHP 的 php 扩展文件,node 的 html 扩展)

转载 作者:行者123 更新时间:2023-12-03 08:13:50 25 4
gpt4 key购买 nike

美好的一天,我想在同一台服务器上处理 php 文件和 html,我希望 html 文件处理端口 8080 上的 Node ,而 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 页面中包含的 Node javascript。我如何在同一服务器上处理 php 和 html 这两种类型的文件?

最佳答案

这样不行。

问题是:当您使用 nginx+php 时,nginx 并不真正运行 php filename.php 当您点击 localhost/filename.php 时。有php-fpm nginx 向它发送请求。然后,php-fpm 运行实际脚本,创建正确的 $_SERVER$_GET 等。

node 情况下,您没有任何 node-fpm 服务。 Nginx 不会运行 node filename.html。您需要在 8080 端口设置提供 http 连接的真实 Node 进程,因为 nginx 所做的只是将实际的 http 连接“传递”到 http://localhost:8080,如您所指定。

了解如何让 Node http 服务器正常工作。

附注线索:更频繁地查看 nginx 日志(Ubuntu/Debian 上的 /var/log/nginx/*)。 :)

关于javascript - 在 Nginx 上运行 PHP 和 Node.js(PHP 的 php 扩展文件,node 的 html 扩展),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34035288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com