[英]502 Bad Gateway Nginx after server restore
So I've got a Ubuntu server that I'm trying to restore from a backup. 所以我有一个Ubuntu服务器,我试图从备份恢复。 And when a dummy PHP version page I get 502 Bad Gateway.
当一个虚拟的PHP版本页面,我得到502 Bad Gateway。 What have I tried to fix it?
我试图修复它的是什么? Quite a few things including the answers from this related question - nginx 502 bad gateway
相当多的事情,包括这个相关问题的答案 - nginx 502坏网关
This is my default config with Ubuntu 这是我使用Ubuntu的默认配置
server {
listen 80;
# listen [::]:81 ipv6only=on default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name localhost;
location ~* \.(js|css|png|jpg|jpeg|gif|ico|html)$ {
expires max;
}
location / {
try_files $uri $uri.php $uri.php/$args /index.php?q=$uri&$args $uri/ =404;
index index.php index.html index.htm;
rewrite ^(.*)$ /$1.php;
}
location /phpmyadmin {
index index.php;
try_files $uri $uri/ =404;
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
EDIT: Here's what I think is the relevant part of the log 编辑:这是我认为是日志的相关部分
2017/08/11 13:18:13 [error] 27759#0: *270 connect() failed (111: Connection refused) while connecting to upstream, client: 66.61.18.112, server: domain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "[IP ADDRESS]", referrer: "http://[IP ADDRESS]/phpmyadmin/index.php"
EDIT 2: 编辑2:
Here's the result when I run ps aux | grep php-fpm
这是我运行
ps aux | grep php-fpm
时的结果 ps aux | grep php-fpm
: ps aux | grep php-fpm
:
mre 21685 0.0 0.0 11756 932 pts/0 S+ 10:42 0:00 grep --color=auto php-fpm
root 32721 0.0 1.0 269300 11168 ? Ss Aug11 0:30 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data 32724 0.0 0.4 269300 4540 ? S Aug11 0:00 php-fpm: pool www
www-data 32725 0.0 0.4 269300 4540 ? S Aug11 0:00 php-fpm: pool www
Edit 3: 编辑3:
Here's what's uncommented out of my php-fpm.conf 这是我的php-fpm.conf中没有注释的内容
[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /var/run/php5-fpm.pid
; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php5-fpm.log
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php5/fpm/pool.d/*.conf
Edit 4: 编辑4:
Here's what's uncommented from my www.conf: 以下是我在www.conf中没有注释的内容:
listen = 127.0.0.1:9000
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chdir = /
Edit 5: 编辑5:
My nginx log after I try to go to index.php: 我尝试去index.php之后的nginx日志:
[error] 29393#0: *23 connect() failed (111: Connection refused) while connecting to upstream, client: [Computer IP Address], server: [Subdomain.domain.com], request: "GET /favicon.ico HTTP/1.1", upstream:"http://127.0.0.1:8080/favicon.ico", host: [Server IP], referrer: "http://[Server IP]/index.php"
So I checked out my nginx config and found these lines: 所以我检查了我的nginx配置并找到了这些行:
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
Then I went to /etc/nginx/conf.d/*.conf
and saw that in the servers.conf
file, there was a config for a sub domain that I planned on using but won't anymore so I deleted it. 然后我去了
/etc/nginx/conf.d/*.conf
,看到在servers.conf
文件中,有一个我计划使用的子域的配置,但不再这样了,所以我删除了它。 This was a big part of the problem because nginx was looking in this config first and that's why the errors included this subdomain. 这是问题的一个重要部分,因为nginx首先查看此配置,这就是错误包含此子域的原因。
As for the php problems, I switched my config to fastcgi_pass unix:/run/php/php7.0-fpm.sock;
至于php问题,我将配置切换到
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
and that seems to have fixed the problem. 这似乎解决了这个问题。
Try to replace 尝试更换
fastcgi_pass unix:/var/run/php5-fpm.sock;
in your nginx config to 在你的nginx配置中
fastcgi_pass 127.0.0.1:9000;
Because if your PHP-FPM config you use TCP instead of socket (it's OK). 因为如果您的PHP-FPM配置使用TCP而不是套接字(没关系)。
You have to change this line 你必须改变这一行
from: 从:
listen = 127.0.0.1:9000
to: 至:
listen = /var/run/php5-fpm.sock
in your www.conf file 在您的www.conf文件中
Don't forget to restart php. 别忘了重启php。
Explanation: 说明:
If you look at your nginx virtual host fastcgi_pass parameter 如果你看一下你的nginx虚拟主机fastcgi_pass参数
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
you'll see that you are pointing processing of php files to php5-fpm socket but in your www.conf file php is listening port 9000 which is why you should change it to /var/run/php5-fpm.sock 你会看到你正在将php文件的处理指向php5-fpm socket,但在你的www.conf文件中php是监听端口9000,这就是为什么你应该将它改为/var/run/php5-fpm.sock
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.