簡體   English   中英

服務器恢復后502 Bad Gateway Nginx

[英]502 Bad Gateway Nginx after server restore

所以我有一個Ubuntu服務器,我試圖從備份恢復。 當一個虛擬的PHP版本頁面,我得到502 Bad Gateway。 我試圖修復它的是什么? 相當多的事情,包括這個相關問題的答案 - nginx 502壞網關

這是我使用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;
}
}

編輯:這是我認為是日志的相關部分

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"

編輯2:

這是我運行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 

編輯3:

這是我的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

編輯4:

以下是我在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 = /

編輯5:

我嘗試去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"

所以我檢查了我的nginx配置並找到了這些行:

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

然后我去了/etc/nginx/conf.d/*.conf ,看到在servers.conf文件中,有一個我計划使用的子域的配置,但不再這樣了,所以我刪除了它。 這是問題的一個重要部分,因為nginx首先查看此配置,這就是錯誤包含此子域的原因。

至於php問題,我將配置切換到fastcgi_pass unix:/run/php/php7.0-fpm.sock; 這似乎解決了這個問題。

嘗試更換

fastcgi_pass unix:/var/run/php5-fpm.sock;

在你的nginx配置中

fastcgi_pass 127.0.0.1:9000;

因為如果您的PHP-FPM配置使用TCP而不是套接字(沒關系)。

你必須改變這一行

從:

listen = 127.0.0.1:9000

至:

listen = /var/run/php5-fpm.sock

在您的www.conf文件中

別忘了重啟php。

說明:

如果你看一下你的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;
}

你會看到你正在將php文件的處理指向php5-fpm socket,但在你的www.conf文件中php是監聽端口9000,這就是為什么你應該將它改為/var/run/php5-fpm.sock

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM