Nginx/Fcgi:index.php 伪别名位置问题
Nginx/Fcgi: index.php issue with pseudo-alias location
Debian Jessie 上的 Nginx 1.6.2
我想将所有 example.com/forum/ 请求映射到 /path/to/htdocs/phpbb 并切断 /forum/ URI 中的部分。 Whosebug 上有人推荐 "rewrite" 解决方案而不是 "alias",因为存在一些错误。
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/(.*)$ / break;
location ~ .+\.php$
{
rewrite ^/forum/(.*)$ / 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" 行后:
directory index of "/path/to/htdocs/phpbb/" is forbidden
将 "index" and/or "try_files" 行移动到该位置后区块:
index.php served without passing over to php-fpm…
好的,我的配置有什么问题?有什么提示吗?
好吧,别名是有问题的(重写 也...),但是如果你避免使用 try_files 而是使用 if (即使邪恶......)它应该工作!
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)
{
return 404;
}
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root;
fastcgi_param SCRIPT_NAME ;
fastcgi_param PATH_INFO ;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
}
phpinfo() 看起来不错,但还有一个问题:它安全吗?
Debian Jessie 上的 Nginx 1.6.2
我想将所有 example.com/forum/ 请求映射到 /path/to/htdocs/phpbb 并切断 /forum/ URI 中的部分。 Whosebug 上有人推荐 "rewrite" 解决方案而不是 "alias",因为存在一些错误。
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/(.*)$ / break;
location ~ .+\.php$
{
rewrite ^/forum/(.*)$ / 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" 行后:
directory index of "/path/to/htdocs/phpbb/" is forbidden
将 "index" and/or "try_files" 行移动到该位置后区块:
index.php served without passing over to php-fpm…
好的,我的配置有什么问题?有什么提示吗?
好吧,别名是有问题的(重写 也...),但是如果你避免使用 try_files 而是使用 if (即使邪恶......)它应该工作!
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)
{
return 404;
}
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root;
fastcgi_param SCRIPT_NAME ;
fastcgi_param PATH_INFO ;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
}
phpinfo() 看起来不错,但还有一个问题:它安全吗?