简体   繁体   中英

Nginx throw 502 bad gateway on php5-fpm setup

This is my setup detail

Nginx.conf

user  nginx;
worker_processes  8;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  4096;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;


    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

}

My conf file , by the filename default insides sites-available and sites-enabled

server {
    server_name www.subdomain.mywebsite.com subdomain.mywebsite.com;
    access_log /srv/www/subdomain.mywebsite.com/logs/access.log;
    error_log /srv/www/subdomain.mywebsite.com/logs/error.log;
    root /srv/www/subdomain.mywebsite.com/public_html;

    location / {

        index index.html index.htm index.php;
    }


    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME /srv/www/subdomain.mywebsite.com/public_html$fastcgi_script_name;
    }
}

When I run html file by my domain, its work fine.

But if i go to php file, such as example

subdomain.mywebsite.com/info.php

It give this 502 bad gateway error of nginx

Php5-fpm is running when the issue occur

root@ubuntu:/etc/nginx/sites-available# service php5-fpm status
php5-fpm start/running, process 12196

This is how a typical response works: a request is sent to Nginx, which sends that request to PHP-FPM on behalf of the client browser; PHP-FPM responds with its evaluated code, then sends that response back to Nginx. In your situation, this is still happening. The problem is that PHP-FPM is not sending the result you want. You want code to be evaluated, but instead it is saying it cannot read the code, more or less, so it tells Nginx that it dun goofed, and so Nginx tells the client browser that the "gateway" (the upstream server, being PHP-FPM) is being a douche; that is, it sends the client browser a 502 response, because it cannot show up to the boss empty handed.

What does this mean?

It means, unsurprisingly, that permissions are wrong. Permissions are preventing PHP-FPM from doing its thing. Find PHP-FPM's www.conf file, and adjust the listen.owner , listen.group , listen.mode , user , and group settings. Also, just use a socket. This is configured in the same place. Actually, the permission settings I just listed will only work with sockets. Nevertheless, if you want to continue running Nginx on a listening port, it is still a permissions issue.

Your logs would easily state this. Did you really investigate this problem? Search engines are probably inundated with results pertaining to this very information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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