Nginx 1.6.2 on Debian Jessie
我想映射所有example.com/forum/请求到/path/到/htdocs/phpbb并切断URI中的/forum/部分。有人在Stackoverflow上推荐"重写"解决方案,而不是"别名",因为有一些bug。
server
{
listen [::]:80;
server_name example.com;
root /var/www/html;
index index.php index.html;
#try_files $uri $uri/ =404;
location /forum/
{
root /path/to/htdocs/phpbb;
rewrite ^/forum/(.*)$ /$1 break;
location ~ .+'.php$
{
rewrite ^/forum/(.*)$ /$1 break;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
}
示例配置工作正常- example.com/forum/viewtopic.php执行脚本/path/to/htdocs/phpbb/viewtopic.php -但是example.com/ (index.php)不起作用:
"/var/www/html/index.php" failed (2: No such file or directory)
从服务器块中删除"index"行后:
目录索引"/path/to/htdocs/phpbb/"是禁止的
将"index"和/或"try_files"行移动到location块后:
index.php没有传递到php-fpm…
好的,我的配置有什么问题?有提示吗?
好吧,别名是有bug的(重写太…),但如果你避免try_files并使用它来代替(即使邪恶…)它应该工作!
server
{
listen [::]:80;
server_name example.com;
root /var/www/html;
location /forum/
{
alias /path/to/htdocs/phpbb/;
index index.php index.html;
location ~ "^(/forum/)(.+'.php)(/.+){0,1}$"
{
if (!-f $document_root$2)
{
return 404;
}
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$2;
fastcgi_param SCRIPT_NAME $1$2;
fastcgi_param PATH_INFO $3;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
}
phpinfo()看起来很好,但一个问题仍然存在:是安全的吗?