In my site I get a 502 bad gateway after implementing the following configuration:
# Default server configuration
2 #
3 server {
4 listen 80;
5 listen [::]:80;
6 server_name microurb.club;
7 return 301 http://www.microurb.club;
8 }
9
10 server {
11 listen 80;
12 listen [::]:80;
13
14 # SSL configuration
15 #
16 # listen 443 ssl default_server;
17 # listen [::]:443 ssl default_server;
18 #
19 # include snippets/snakeoil.conf;
20
21 root /var/www/microurb.com/public_html;
22
23 # Add index.php to the list if you are using PHP
24 index index.php index.html index.htm index.nginx-debian.htm;
25
26 server_name www.microurb.club;
27 ·
28 include global/restrictions.conf;
29 include global/wordpress.conf;
30 ·
31 # location / {
32 # # First attempt to serve request as file, then
33 # # as directory, then fall back to displaying a 404.
34 # try_files $uri $uri/ =404;
35 # }
36
37 location ~ \.php$ {
38 include snippets/fastcgi-php.conf;
39 fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
40 }
41
42 # Allow access to the ACME Challenge directory
43 location ~ /\.well-known\/acme-challenge {
44 allow all;
45 }
46
47 include custom_config_files/x_protection.conf;
48 }
49
50 server {
51 listen 443 ssl http2;
52 listen [::]:443 ssl http2;
53 server_name microurb.club;
54 return 301 https://www.microurb.club;
55 include ssl/ssl_general.conf;
56 include ssl/ssl_microurb.com.conf;
57 }
58
59 server {
60 listen 443 ssl http2;
61 listen [::]:443 ssl http2;
62 server_name www.microurb.club;
63
64 include ssl/ssl_general.conf;
65 include ssl/ssl_microurb.com.conf;
66
67 root /var/www/microurb.com/public_html;
68
69 # Add index.php to the list if you are using PHP
70 index index.html index.php;
71
72 location ~ \.php$ {
73 include snippets/fastcgi-php.conf;
74 fastcgi_pass unix:/var/run/php7.0-fpm.sock;
75 }
76
77 include custom_config_files/x_protection.conf;
78 }
79
I did a:
sudo tail -30 /var/log/nginx/error.log
And received the following errors, but I do not know what they mean:
PHP message: PHP Notice: Undefined index: success in /var/www/microurb.com/public_html/index.php on line 295" while reading upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "www.microurb.club"
2018/12/25 20:07:05 [crit] 18408#18408: *40 connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php7.0-fpm.sock:", host: "www.microurb.club"
2018/12/25 20:07:06 [error] 18408#18408: *40 open() "/var/www/microurb.com/public_html/favicon.ico" failed (2: No such file or directory), client: 24.55.9.54, server: www.microurb.club, request: "GET /favicon.ico HTTP/2.0", host: "www.microurb.club", referrer: "https://www.microurb.club/"
2018/12/25 20:07:10 [crit] 18408#18408: *40 connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php7.0-fpm.sock:", host: "www.microurb.club"
2018/12/25 20:07:20 [crit] 18408#18408: *40 connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 24.55.9.54, server: www.microurb.club, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/var/run/php7.0-fpm.sock:", host: "www.microurb.club"
I believe the issue has root in my configuration above, but I am not sure where. When I try to uncomment this block:
31 # location / {
32 # # First attempt to serve request as file, then
33 # # as directory, then fall back to displaying a 404.
34 # try_files $uri $uri/ =404;
35 # }
I get an error after running sudo nginx -t
saying that I have nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/microurb.com:31
, but I only have one. Not sure why I get that error.
Your fastcgi_pass paths on lines 39 and 74 don't match (74 is missing a /php). Since it's complaining about the path on line 74, change that to match line 39: