Python 在 stderr 中发送的 FastCGI:“主脚本未知” - nginx 和 silex
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26722482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FastCGI sent in stderr: "Primary script unknown" - nginx and silex
提问by Henrique Gon?alves
I'm getting this error on a server where I've deployed a Silex project.
我在部署 Silex 项目的服务器上收到此错误。
In this server I already had nginx passing requests from /to a Flask app running in port 5000.
在这个服务器中,我已经让 nginx 将请求传递/到在端口 5000 中运行的 Flask 应用程序。
So, after pulling the new project from my repository to /var/www/newprojectI was trying to configure nginx so a request to http://xxx.xxx.xxx.xxx/newprojectwould root to /var/www/newprojectwhich is a silex app.
因此,在将新项目从我的存储库中提取到我之后,/var/www/newproject我试图配置 nginx,以便请求http://xxx.xxx.xxx.xxx/newproject根到/var/www/newproject它是一个 silex 应用程序。
I've searched the web and all the configs I've found don't solve my problem. Accessing any route, returns 404.
我在网上搜索过,我发现的所有配置都不能解决我的问题。访问任何路由,返回 404。
My entire config is like this:
我的整个配置是这样的:
server {
listen 80;
server_name xxx.xxx.xxx.xxx;
access_log /var/log/myproject/nginx_access.log;
error_log /var/log/myproject/nginx_error.log;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
location /newproject {
root /var/www;
try_files $uri $uri/ =404;
index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/newproject/index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME /var/www/newproject$fastcgi_script_name;
include fastcgi_params;
}
location / {
root /opt/myproject;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://xxx.xxx.xxx.xxx:5000;
break;
}
}
}
What am I missing here?
我在这里缺少什么?
Thank you.
谢谢你。
UPDATE:
更新:
Tried a new config (as below) and now accessing http://xxx.xxx.xxx.xxx/newproject/SOME_PATHI have a 404.
尝试了一个新的配置(如下),现在访问http://xxx.xxx.xxx.xxx/newproject/SOME_PATH我有一个 404。
open() "/var/www/newproject/SOME_PATH" failed (20: Not a directory)
open() "/var/www/newproject/index.php/SOME_PATH" failed (20: Not a directory)
location /newproject {
root /var/www/;
index index.php index.html index.htm;
location ~ ^/newproject/(.+\.php)$ {
try_files $uri =404;
root /var/www/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS off;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi_params;
}
location ~* ^/newproject/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /var/www/;
}
}
采纳答案by Henrique Gon?alves
So, I've managed to solve my problem following this Site Configuration for Nginx Sub-Folder
因此,我按照Nginx 子文件夹的站点配置设法解决了我的问题
Now my config is:
现在我的配置是:
server {
listen 80;
server_name xxx.xxx.xxx.xxx;
root /opt/myproject;
access_log /var/log/myproject/nginx_access.log;
error_log /var/log/myproject/nginx_error.log;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
location /newproject {
root /var/www;
index index.php index.html index.htm;
rewrite ^/newproject/(.*)$ /newproject/ break;
try_files $uri $uri/ /newproject/index.php?q=$uri&$args;
location ~ .*\.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
location / {
root /opt/myproject/;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://xxx.xxx.xxxx.xxx:5000;
break;
}
}
}
Since newproject depends on myproject, I kept their config in the same file and the same nginx access and error log files.
由于 newproject 依赖于 myproject,我将它们的配置保存在同一个文件和同一个 nginx 访问和错误日志文件中。
回答by TheBelgarion
dont forget to check user:group for nginx && php-fpm
不要忘记检查 user:group for nginx && php-fpm
Error Message will be the same if php-fpm is still running "apache" user and you already switched the user "nginx" on nginx and on the http directory!
如果 php-fpm 仍在运行“apache”用户并且您已经在 nginx 和 http 目录上切换了用户“nginx”,则错误消息将相同!
and reload both
并重新加载两者

