在 利用apache伪静态规则重写lighttpd伪静态规则的方法 文中提到lighttpd伪静态规则不可以重复
假如您的规则最后如下:
url.rewrite = (
#zblog规则
"^(.*)/read-(.*).html$"=>"$1/index.php?id=$1",
#phpwind规则
"^(.*)/read-(.*).html$" => "$1/read.php?tid=$2&page=$3&fpage=$4"
)
这样是不可以的
因为重复了if
"^(.*)/read-(.*).html$"
所以会导致服务器无法重启
在nginx服务器上也是会遇到类似问题的。
您购买独立主机如果是nginx服务器,您可能不止开一个站,多个站的伪静态规则未必不会冲突。
所以在欢迎您继续收看友声网卡卡北的原创“软文”同时,也请您继续看下去,说不定能用上。
在 使用phpStudy套件,php-fastcgi模式下,nginx添加虚拟主机(多站点)配置 一文中讲道,在nginx下如何添加多站点。
那还是用此文中的phpstudy套件进行演示:
以链接:http://hi.ys166.com/read-573.html
找到文中nginx配置代码:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root "D:/phpStudy/WWW";
location / {
index index.html index.htm index.php l.php;
autoindex off;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
和
server {
listen 80;
server_name 127.0.0.2;
#charset koi8-r;
#access_log logs/host.access.log main;
root "D:/phpStudy/WWW2";
location / {
index index.html index.htm index.php l.php;
autoindex off;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
分别在这两个站点中的
root "D:/phpStudy/WWW";
和
root "D:/phpStudy/WWW2";
下分别添加:
include D:/phpStudy/WWW/.htaccess;
和
include D:/phpStudy/WWW2/.htaccess;
同时在每个站点下添加:
location ~ /.ht {
deny all;
}
位置没有太大要求,我为了好截图,添加的比较靠上,这段代码就是过滤.ht开头的文件,防止.htaccess文件被下载。
改后如图:

效果演示:
127.0.0.1为phpwind9.0.1
127.0.0.2为discuz x3.3
这两个论坛程序默认规则
是有重复
的。分开写后就不会出现问题了。
本文源自:友声网博客,地址:http://hi.ys166.com/read-575.html
本文介绍了在nginx服务器上如何处理多个站点的伪静态规则,以避免因规则重复导致的服务器无法重启问题。通过添加代码过滤.htaccess文件,防止其被下载,并提供了一个实例演示了在phpStudy套件中为不同站点设置伪静态的步骤。
1万+

被折叠的 条评论
为什么被折叠?



