在 Ubuntu 中使用 nginx 和 php7.0-fpm 的 Laravel 5.4 的 502 错误网关

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41907811/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:13:10  来源:igfitidea点击:

502 Bad Gateway for Laravel 5.4 with nginx and php7.0-fpm in Ubuntu

phplaravelubuntunginxlaravel-5

提问by devo

I have my Laravel 5.4app setup in Ubuntu 16.04server with nginxand php7.0-fpm, it gives

我有我Laravel 5.4的应用程序的设置Ubuntu 16.04与服务器nginxphp7.0-fpm,它给

502 Bad Gateway

Nginx virtualhost config,

Nginx 虚拟主机配置,

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /var/www/html/laravel/public;
    index index.php index.html;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        include                  fastcgi_params;
        fastcgi_keep_conn on;
        fastcgi_index            index.php;
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php7.0-fpm.sock;
    }
}

Tried the following but still not working,

尝试了以下但仍然无法正常工作,

Changed fastcgi_pass unix:/var/run/php7.0-fpm.sock;to fastcgi_pass 127.0.0.1:9000;

改变fastcgi_pass unix:/var/run/php7.0-fpm.sock;fastcgi_pass 127.0.0.1:9000;

Changed try_files $uri $uri/ /index.php?$query_string;to try_files $uri $uri/ /index.php$is_args$args;

改变try_files $uri $uri/ /index.php?$query_string;try_files $uri $uri/ /index.php$is_args$args;

Restarted service after each change,

每次更改后重新启动服务,

service nginx restart
service php7.0-fpm restart

I can access only the main route with this config,

我只能使用此配置访问主路由,

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www/html/laravel/public;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

回答by devo

Updating one line with default php based config worked,

使用基于 php 的默认配置更新一行有效,

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www/html/laravel/public;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}

Here changed try_files $uri $uri/ =404;to try_files $uri $uri/ /index.php?$query_string;

这里改变try_files $uri $uri/ =404;try_files $uri $uri/ /index.php?$query_string;