在我的站点中,执行以下配置后,我得到一个 502 bad gateway:
# 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
我做了一个:
sudo tail -30 /var/log/nginx/error.log
并收到以下错误,但我不知道它们是什么意思:
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"
我相信问题根源于我上面的配置,但我不确定在哪里。当我尝试取消注释此块时:
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 # }
运行后我得到一个错误,sudo nginx -t
说我有nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/microurb.com:31
,但我只有一个。不知道为什么我会收到那个错误。
第 39 行和第 74 行的 fastcgi_pass 路径不匹配(74 缺少 /php)。因为它抱怨第 74 行的路径,所以将其更改为匹配第 39 行: