2

I've been searching for hours. I've found so many similar cases and can't figure out why mine doesn't match. When I go to my web address I was getting a 502 Bad Gateway error. Now with the current setup, it's just a blank page. I'm guessing a file can't be found but I haven't been able to find any errors or things missing.

I'm on Ubuntu 16.04 LTS, Nginx 1.10, PHP 7.0 FPM, MySQL. Do I need to share anything else? Thanks to everyone for their help.

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    client_body_buffer_size 128k;
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##

    ##
    # Virtual Host Configs
    ##

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

    client_max_body_size 100M;
}

/etc/nginx/sites-available/mysite.conf

server {
    server_name my site dot com;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/letsencrypt/live/mysite/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mysite/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/mysite/fullchain.pem;
    include /etc/nginx/snippets/ssl.conf;

    root /var/www/mysite;
    index index.php index.html index.htm;

    location / {
            try_files $uri $uri/ /index.php$is_args$args;
    }

    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;
    }
    #location ~ \.php$ {
    #        try_files $uri =404;
    #        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #
    #        fastcgi_index index.php;
    #        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #        include fastcgi_params;
    #}
  }

/etc/nginx/sites-available/default

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  root /var/www/html;
  index index.php index.html index.htm index.nginx-debian.html;

  server_name my_IP;

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

/var/log/php7.0-fpm.log

[17-Nov-2017 15:23:13] NOTICE: fpm is running, pid 26582
[17-Nov-2017 15:23:13] NOTICE: ready to handle connections
[17-Nov-2017 15:23:13] NOTICE: systemd monitor interval set to 10000ms
[17-Nov-2017 15:37:03] NOTICE: Terminating ...
[17-Nov-2017 15:37:03] NOTICE: exiting, bye-bye!
[17-Nov-2017 15:37:03] NOTICE: configuration file /etc/php/7.0/fpm/php-fpm.conf test is successful

[17-Nov-2017 15:37:03] NOTICE: fpm is running, pid 26738
[17-Nov-2017 15:37:03] NOTICE: ready to handle connections
[17-Nov-2017 15:37:03] NOTICE: systemd monitor interval set to 10000ms

/var/log/nginx/error.log

2017/11/17 15:55:47 [crit] 26937#26937: *373 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 141.8.142.17, server: mysite, request: "GET /wp-content/uploads/2014/09/image005.jpg HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "mysite"
2017/11/17 18:16:35 [crit] 26966#26966: *671 connect() to unix:/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: IP, server: my_IP, request: "GET /error.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "my_IP"
Mac Zoller
  • 21
  • 4
  • Please do a curl of the index.php file, then edit your question to give Nginx and PHP access and error logs. I only want to see logs related to that one curl right now, check timestamps. PHP access logs aren't turned on by default, but can be very useful - Google will tell you how to do that. – Tim Nov 17 '17 at 17:50
  • @Tim just updated the question with that you asked for. When I do curl index.php in the dir, it says cannot resolve. – Mac Zoller Nov 17 '17 at 18:37
  • You've specified the wrong location for the .sock file on your file system, or permissions are incorrect. Use the shell to find the file and check permissions relative to the user Nginx is running as. I find it easier to get http sockets going than unix sockets. – Tim Nov 17 '17 at 20:45

1 Answers1

1

if your config file has this line:

fastcgi_pass  127.0.0.1:9000;

and in your /etc/php/7.0/fpm/pool.d/www.conf you have at line where it shows

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

then you need to replace it with

listen = 127.0.0.1:9000

save file and restart php:

service php7.0-fpm restart

It should work!

Mike
  • 11
  • 1