

- nginx伪静态
- 发布时间:2010-09-27 09:20:05 浏览数:7621 发布者:superadmin 设置字体【大 中 小】
用nginx创建了一下站点!安装了dzx1
方法如下:
1. 在需要使用.htaccess文件的目录下新建一个.htaccess文件,
如本人的一个Discuz论坛目录:
vim /opt/wwwroot/discuz/.htaccess
2. 在里面输入规则,我这里输入Discuz的伪静态规则:
# nginx rewrite rule
rewrite ^(.*)/archiver/((fid|tid)-[w-]+.html)$ $1/archiver/index.php?$2 last;
rewrite ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3 last;
rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3 last;
rewrite ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3 last;
rewrite ^(.*)/tag-(.+).html$ $1/tag.php?name=$2 last;
# end nginx rewrite rule
wq保存退出。
注意一下:在这里规则按照上面写就可以的!当然rewrite不能为大写
3. 修改nginx配置文件:
vim /usr/local/webserver/nginx/conf/nginx.conf
4. 在需要添加伪静态的虚拟主机的server{}中引入.htaccess文件,
server
{
listen 80;
server_name www.aa.com;
access_log /opt/logs/aa.log;
root /opt/wwwroot/discuz;
location /
{
index index.html index.htm index.php;
}
include /opt/wwwroot/discuz/.htaccess;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
wq保存退出。
5. 重新加载nginx配置文件:
重新打开网页看看,如果伪静态正常就证明你的rewrite rule语法是正确的。