服务器:CentOs x86_64
/etc/php-fpm.d/webuser1.conf
[webuser1]
listen = 127.0.0.1:9001
listen.allowed_clients = 127.0.0.1
user = webuser1
group = webuser1
pm = dynamic
pm.max_children = 15
pm.start_servers = 3
pm.min_spare_servers = 1
pm.max_spare_servers = 5
pm.max_requests = 2000
request_slowlog_timeout = 5
slowlog = /home/webuser1/tmp/logs/webuser1.slow.log
php_admin_value[error_log] = /home/webuser1/tmp/logs/webuser1.error.log
php_admin_flag[log_errors] = on
/etc/nginx/conf.d/web1.conf
server {
listen 80;
server_name c64p1.v.lab.gavika.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/webuser1/www/public;
index index.html index.htm index.php;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
在 Nginx 日志中,我有:
2013/05/18 15:21:52 [error] 2943#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.122.1, server: c64p1.v.lab.gavika.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "c64p1.v.lab.gavika.com"
我怎样才能让它工作?
答案1
您将root
指令放在了错误的地方。
root
应该在块中定义server
,而不是在每个location
块中定义。这是最常见的 nginx 配置错误。
root
要解决该问题,请从每个块中删除所有指令location
,并将正确的root
指令放在server
块内,而不是任何内location
。
答案2
您能分享一下您正在测试的哪些标头,它们会给您带来这些结果吗?看起来您只是通过浏览器执行了 Get root (/) 请求?
如果缺少有关输入标头的更多信息或如何测试配置,则很可能您会在配置中遇到位置问题。
我的两条建议是:
1) 查看 Nginx 位置的帮助页面。Nginx Wiki(http://wiki.nginx.org/配置) 是入门的好去处。此外,Martin Fjordvald 的入门书 (http://blog.martinfjordvald.com/2010/07/nginx-primer/) 的位置配置很好。
2) 如果我的 c64p1.v.lab.gavika.com 配置无法正常工作,我会回退到基于本地主机服务器的简单 Nginx 配置,并首先使本地主机配置正常工作。