当我尝试使用 nginx 连接到我的 lumen api 时返回 502

Posted

技术标签:

【中文标题】当我尝试使用 nginx 连接到我的 lumen api 时返回 502【英文标题】:502 returned when I try connect to my lumen api using nginx 【发布时间】:2020-01-13 17:03:07 【问题描述】:

我声明了以下服务器块:

server 
    listen 80;
    server_name mywebsite.com;

    root /var/www/mywebsite/frontend/build;
    index index.html;

    location / 
        try_files $uri $uri/ =404;
    


server 
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/mywebsite/backend/public;
    index index.php index.html index.htm;

    server_name api.mywebsite.com;

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

    location ~ \.php$ 
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    

第二个块中的根目录是我的 Lumen php 后端。 现在,当我向它发出请求时:http://api.mywebsite.com/categories 然后我得到一个 502 bad gateway 问题。 我怎样才能弄清楚该怎么做才能解决这个问题?

【问题讨论】:

你检查过nginxerror.log吗? 【参考方案1】:

看到这个fastcgi_pass unix:/var/run/php7.2-fpm.sock; 线...

调查/etc/php/7.2/fpm/pool.d/www.conf 即使用 nginx 用户和/或组,或 www-data 用户和/或组...

listen = /run/php/php7.2-fpm.sock

listen.owner = nginx # www-data if you config nginx to use www-data user
listen.group = nginx
listen.mode = 0660

【讨论】:

以上是关于当我尝试使用 nginx 连接到我的 lumen api 时返回 502的主要内容,如果未能解决你的问题,请参考以下文章