我有一个具体的5网站,可以在apache服务器中“开箱即用”。但是我在nginx中运行它时遇到了很多麻烦。
以下是我正在使用的nginx配置:
server {
root /home/test/public;
index index.php;
access_log /home/test/logs/access.log;
error_log /home/test/logs/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ index.php;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# pass the PHP scripts to FastCGI server listening on unix socket
#
location ~ \.php($|/) {
fastcgi_pass unix:/tmp/phpfpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
我能够获得主页,但内页有问题。内页显示“拒绝访问”。可能重写不起作用,实际上我认为它的查询和尝试直接执行php文件而不是通过具体的调度程序。
我完全迷失在这里。
提前感谢您的帮助。
答案 0 :(得分:3)
将配置更改为:
server {
root /home/test/public;
index index.php;
access_log /home/test/logs/access.log;
error_log /home/test/logs/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.php/$request_uri;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
# pass the PHP scripts to FastCGI server listening on unix socket
#
location ~ \.php($|/) {
set $script $uri;
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_intercept_errors on;
fastcgi_pass unix:/tmp/phpfpm.sock;
}
location ~ /\.ht {
deny all;
}
}
由于宿醉和他在serverfault中提供的link,它确实有效。
我仍然不清楚我做错了什么,也许nginx专家可以帮助我理解。