繁体   English   中英

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

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

我在带有nginxphp7.0-fpm Ubuntu 16.04服务器中设置了我的Laravel 5.4应用程序,它提供了

502 Bad Gateway

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

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

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

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

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

service nginx restart
service php7.0-fpm restart

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

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

使用基于 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;
        }
}

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

第一次安装: sudo apt install php-fpm

然后检查/etc/php/7.4/fpm ,确保您的 php 7.0 -fpm.sock、php 7.4 -fpm.sock 或7.x 版本

fastcgi_pass unix:/run/php/php7.4-fpm.sock;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM