无法在 nginx 中隐藏 index.php 以进行社交引擎重写
Posted
技术标签:
【中文标题】无法在 nginx 中隐藏 index.php 以进行社交引擎重写【英文标题】:Cannot hide index.php in nginx for socialengine rewrite 【发布时间】:2014-03-28 02:57:45 【问题描述】:我是 nginx 重写的新手,但我正在尝试在 nginx 上运行 socialengine。我有以下重写规则,这些规则似乎在除 domain.com/index.php 或 domain.com 之外的所有地方都有效。这些规则似乎适用于所有其他链接(不在 /install/ 路径中,我已经知道需要另一组重写规则)。
我的规则缺少什么?
server
listen 8080;
server_name domain.com www.domain.com;
root /home/user/public_html;
index index.php;
#charset koi8-r;
#access_log logs/host.access.log main;
# BLOCKS ACCESS TO . FILES (.svn, .htaccess, ...)
location ~ /\.
deny all;
location /
try_files $uri $uri/ @seRules;
location @seRules
rewrite /index\.php /index.php?rewrite=2;
rewrite ^(.*)$ /index.php?rewrite=1;
location ~* \.php$
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass_request_body off;
client_body_in_file_only clean;
fastcgi_param REQUEST_BODY_FILE $request_body_file;
error_page 404 /404.html;
location = /404.html
root /home/user/public_html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html
root /home/user/public_html;
【问题讨论】:
【参考方案1】:只需在 conf 中包含以下内容。这也会隐藏 index.php..
位置 ~ index.php
root /home/user/public_html;
rewrite .* /index.php?rewrite=1 break;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/user/public_html$fastcgi_script_name;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT /home/user/public_html;
fastcgi_pass_request_body off;
client_body_in_file_only clean;
fastcgi_param REQUEST_BODY_FILE $request_body_file;
【讨论】:
【参考方案2】:location /
if (!-e $request_filename) rewrite ^(.*)$ /index.php?rewrite=1 last;
# avoid redirect / -> /index.php
if ($request_uri = '/') rewrite ^(.*)$ /index.php?rewrite=1 last;
【讨论】:
以上是关于无法在 nginx 中隐藏 index.php 以进行社交引擎重写的主要内容,如果未能解决你的问题,请参考以下文章