【发布时间】:2018-02-05 03:31:06
【问题描述】:
我尝试使用 nginx 在同一个域上运行节点 js 和 php。但是 php ("/ajax") 的位置不起作用。我总是收到消息“找不到文件。”。 nginx 日志打印
到目前为止,URL 是 http://localhost:8085/ajax,脚本位于 /var/www/public 文件夹 /ajax 不存在(所有路径都不存在,因为一切都应重定向到 /var/www/public/index.php)
nginx | 2017/08/27 20:47:48 [error] 6#6: *6 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.23.0.1, server: localhost, request: "GET /ajax HTTP/1.1”,上游:“fastcgi://172.23.0.4:9000”,主机:“localhost:8085”
nginx | 172.23.0.1 - - [27/Aug/2017:20:47:48 +0000] "GET /ajax HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, 像壁虎) Chrome/60.0.3112.113 Safari/537.36" "-"
这是我的配置,我要改什么?
upstream react {
server react:3000;
keepalive 8;
}
server {
listen 0.0.0.0:80;
server_name localhost;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://react;
proxy_redirect off;
}
location /ajax {
index index.php index.html;
root /var/www/public;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
client_max_body_size 5m;
}
我试过了
fastcgi_param SCRIPT_FILENAME /var/www/public$fastcgi_script_name;
在某些线程中建议,但这不起作用
【问题讨论】:
-
发布您访问过的 URL 以及该文件应包含的文件夹。还要记住,带有 go 作为该 url 中的路径的 ajax,因此如果您的文件夹没有 ajax,则将找不到要运行的脚本,因此会出现错误
-
感谢您的建议。我更新了我的帖子