http://example.com/工作正常但http://example.com/piwik给了我404。 我无法理解为什么这个配置在Nginx中不起作用。这是我想要提供的网站:
/srv
/blog
index.php
/piwik
index.php
然后是配置文件:
server {
charset utf8;
index index.php;
server_name example.com;
root /srv/blog;
client_max_body_size 10M;
# Deny all ht file useless in nginx
location ~ /\.ht* {
deny all;
}
location /images {
alias /srv/blog/images;
}
location /piwik {
index index.php;
alias /srv/piwik;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^(.+?\.php)(/.*)?$ {
try_files $1 = 404;
include fastcgi_params;
fastcgi_param PATH_INFO $2;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
当我在nginx中激活调试日志时,我可以看到这些奇怪的行:
2014/05/18 14:27:08 [debug] 19676#0: *1 open index "/srv/piwik/index.php"
2014/05/18 14:27:08 [debug] 19676#0: *1 internal redirect: "/piwik/index.php?"
2014/05/18 14:27:08 [debug] 19676#0: *1 rewrite phase: 1
[...]
我的错误在哪里?
谢谢;)
答案 0 :(得分:3)
好的,问题似乎来了
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
我删除了此部分,清理配置并且它可以正常工作。所有配置都是here。
server {
listen *:443 ssl;
index index.php;
server_name example.com;
# We set the default root to /srv/blog
root /srv/blog;
location / {
# Get beautiful urls for the blog
try_files $uri $uri/ /index.php?$args;
}
location /piwik {
# alias does not append location path to the filepath
alias /srv/piwik;
# catch piwik php files and pass it to php-fpm
location ~ /piwik/(.*\.php)(/.*)?$ {
include fastcgi_params;
fastcgi_param HTTPS on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
# catch php files and pass it to php-fpm
location ~ (.*\.php)(/.*)?$ {
include fastcgi_params;
fastcgi_param HTTPS on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}