【问题标题】:FastCGI sent in stderr: "Primary script unknown" - nginx and silex在 stderr 中发送的 FastCGI:“主脚本未知” - nginx 和 silex
【发布时间】:2014-12-30 14:17:46
【问题描述】:

我在部署了 Silex 项目的服务器上遇到此错误。

在这台服务器上,我已经让 nginx 将请求从 / 传递到在端口 5000 中运行的 Flask 应用程序。

所以,在将新项目从我的存储库拉到 /var/www/newproject 之后,我试图配置 nginx,以便对 http://xxx.xxx.xxx.xxx/newproject 的请求将根到 /var/www/newproject,这是一个 silex 应用程序。

我在网上搜索过,我发现的所有配置都不能解决我的问题。 访问任何路由,返回 404。

我的整个配置是这样的:

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;
        }
    }
}

我在这里错过了什么?

谢谢。

更新:

尝试了一个新配置(如下),现在访问 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/;
        }

    }

【问题讨论】:

    标签: python nginx php silex


    【解决方案1】:

    所以,我已经设法解决了这个Site Configuration for Nginx Sub-Folder的问题

    现在我的配置是:

    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/$1 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;
            }
        }
    }
    

    由于 newproject 依赖于 myproject,我将它们的配置保存在同一个文件以及相同的 nginx 访问和错误日​​志文件中。

    【讨论】:

      【解决方案2】:

      别忘了检查 nginx && php-fpm 的 user:group

      如果 php-fpm 仍在运行“apache”用户并且您已经在 nginx 和 http 目录上切换了用户“nginx”,则错误消息将相同!

      并重新加载两者

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-07-02
        • 2021-04-08
        • 2017-11-02
        • 1970-01-01
        • 2020-08-20
        • 2014-04-15
        • 2023-02-06
        • 2016-05-16
        相关资源
        最近更新 更多