我尝试安装 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
。
答案1
PHP 要么没有运行,要么正在运行但未监听该套接字。使用 检查它是否正在运行ps -eF | grep php
,以及是否正在监听。在或其自己的日志文件netstat -tlpn | grep :9000
中检查 PHP 的错误消息。/var/log/syslog
/var/log/
答案2
你在 nginx 框的错误日志中看到任何错误了吗?(可能在 /var/log/nginx/ 的某个地方)这可能有助于发现问题。
--
好吧,我错过了日志中的部分。我认为您的 fastcgi 配置不正确...