Nginx

Nginx:502 壞網關

  • July 8, 2020

我嘗試安裝nginx。我曾經使用 lighttpd,但現在我們必須安裝 nginx。你能幫我配置nginx嗎?

我使用 debian 6。我的nginx.conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
   worker_connections 768;
   # multi_accept on;
}

http {

   ##
   # Basic Settings
   ##

   sendfile on;
   tcp_nopush on;
   tcp_nodelay on;
   keepalive_timeout 65;
   types_hash_max_size 2048;

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

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

   ##
   # Gzip Settings
   ##

   gzip on;
   gzip_disable "msie6";

   ##
   # Virtual Host Configs
   ##

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

我的站點啟用/預設外觀為

server {
   listen   80; ## listen for ipv4; this line is default and implied
   #listen   [::]:80 default ipv6only=on; ## listen for ipv6

   root /var/www; #!
   index index.php index.html index.htm; #1
   access_log      /var/log/nginx/access.log info;
   error_log       /var/log/nginx/error.log info;

   # Make site accessible from http://localhost/
   server_name localhost;

   location / {
           # First attempt to serve request as file, then
           # as directory, then fall back to index.html
           autoindex on;
           # Uncomment to enable naxsi on this location
           # include /etc/nginx/naxsi.rules
   }

   location /doc/ {
           alias /usr/share/doc/;
           autoindex on;
           allow 127.0.0.1;
           deny all;
   }

   location ~ \.php$ {
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           include fastcgi_params;
   }

   # deny access to .htaccess files, if Apache's document root
   # concurs with nginx's one

   location ~ /\.ht {
           deny all;
   }
}

我添加到php.ini

cgi.fix_pathinfo = 0;     

   

php5-cgi 執行為

spawn-fcgi 127.0.0.1 -p 9000 -u www-data -f /usr/bin/php5-cgi

但我收到502 錯誤(網關錯誤)

/var/log/

2012/05/16 15:35:25 [error] 13427#0: *12 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /ndex.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

我沒有執行sqpwn-fcgi=>php-cgi沒有在監聽埠9000

PHP 要麼未執行,要麼正在執行但未在該套接字上偵聽。檢查它是否與 一起執行ps -eF | grep php,並且正在與 一起收聽netstat -tlpn | grep :9000。檢查來自 PHP/var/log/syslog或它自己的日誌文件中的錯誤消息/var/log/

您是否在 nginx 框的錯誤日誌中看到任何錯誤?(可能在 /var/log/nginx/ 中的某個地方)這在發現問題時可能會有所幫助。

好吧,我錯過了日誌中的部分。我認為你的fastcgi的配置不正確……

引用自:https://serverfault.com/questions/389647