Nginx下Discuz!的Rewrite
在上篇《Nginx的Rewrite配置》之后,有不少朋友搜索过来询问相关的设置,于是整理了下,发出来给大家共享。
突然间发现自己写的几篇日志都是关于Nginx的
Rewrite配置,感兴趣的同学可以查看下。
Discuz!在Nginx下的Rewrite
需要说明的是,下网上以前一直流传的Rewrite都是有误的。
下面的Rewrite中百分号前面多了个转移字符“\”,这在Apache中是需要的,而在Nginx中则是不需要的。
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last;
正确的应该是
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
这个错误在基本上目前所有使用Nginx作为服务器,并且开启了Rewrite的网站上存在。包括Discuz!官方,目前已经给cnteacher反馈了。
Nginx实例代码:
server {
listen 80;
server_name www.ccvita.com ccvita.com;
location / {
index index.html index.htm index.php;
root /www/www.ccvita.com;
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;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8694;
fastcgi_param SCRIPT_FILENAME /www/www.ccvita.com$fastcgi_script_name;
}
location /www.ccvita.com-status {
stub_status on;
access_log off;
}
}
相关文档:
《Nginx下Discuz!的Rewrite》:http://www.ccvita.com/319.html
《Nginx下WordPress的Rewrite》:http://www.ccvita.com/319.html
《Nginx的Rewrite配置》:http://www.ccvita.com/319.html
《Nginx的防盗链配置》:http://www.ccvita.com/319.html
实际运行的Nginx下Discuz!的Rewrite。
博主按你的方法还是不能成功:nginx+discuz!还会不能正常显示,下面是我的default配置:
server {
listen 80;
server_name yl93.2288.org;
location / {
index index.php index.html index.htm;
root /var/www;
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;
}
#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 {
}
# 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$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8694;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
}
location /yl93.2288.org-status {
stub_status on;
access_log off;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
#deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#listen 8000;
#listen somename:8080;
#server_name somename alias another.alias;
#location / {
#root html;
#index index.html index.htm;
#}
#}
# HTTPS server
#
#server {
#listen 443;
#server_name localhost;
#ssl on;
#ssl_certificate cert.pem;
#ssl_certificate_key cert.key;
#ssl_session_timeout 5m;
#ssl_protocols SSLv2 SSLv3 TLSv1;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#ssl_prefer_server_ciphers on;
#location / {
#root html;
#index index.html index.htm;
#}
#}
请帮忙看一下
回楼上的,不少地方需要按照实际情况改动的,比如
fastcgi_pass 127.0.0.1:8694
这里
我推荐你看张宴的关于Nginx的教程,很详细
http://www.s135.com/read.php/366.htm
rewrite “^(.*)/date/([0-9]{6})/([0-9]+)/$” /index.php?action=index&setdate=$1&page=$2 last;
rewrite ^(.*)/page/([0-9]+)/$ index.php?page=$1 last;
rewrite ^(.*)/category/([0-9]+)/([0-9]+)/$ /index.php?cid=$1&page=$2 last;
rewrite ^(.*)/category/(.+)/([0-9]+)/$ /index.php?curl=$1&page=$2 last;
rewrite ^(.*)/(archives|search|reg|login|index|links|aboutus)/$ /index.php?action=$1 last;
rewrite ^(.*)/(comments|tagslist|index)/([0-9]+)/$ /index.php?action=$1&page=$2 last;
rewrite ^(.*)/tag/(.+)/([0-9]+)/$ /index.php?action=tags&item=$1&page=$2 last;
rewrite ^(.*)/archives/([0-9]+)/([0-9]+)/$ /index.php?action=show&id=$1&page=$2 last;
rewrite ^(.*)/(.+)/([0-9]+)/$ /index.php?action=show&alias=$1&page=$2 last;
rewrite ^(.*)/user/(.+)/$ /index.php?action=finduser&user=$1 last;
rewrite ^(.*)/uid/([0-9]+)/$ /index.php?action=finduser&uid=$1 last;
帮我看看有什么问题吗?总是不行。
大哥是高手,不知道能不能提供一下joomla的nginx rewrite规则。很多idc都不能解决这个问题,其中说有6年运营经验的华夏名网,他们所有的技术都不能写出joomla的nginx rewrite规则。
@phoenix, 你把joomla在apache下的.htaccess文件帖出来,我来看看
规则的地址是:http://www.jishunxiang.com/htaccess.txt
我google了一下,有个老外写出来规则,但国内同行说不能用。贴出来您参考一下。
if ( $args ~ “mosConfig_[a-zA-Z_]{1,21}(=|\%3d)” ) {
set $args “”;
rewrite ^.*$ http://host/index.php last;
return 403;
}
if ( $args ~ “base64_encode.*\(.*\)” ) {
set $args “”;
rewrite ^.*$ http://host/index.php last;
return 403;
}
if ( $args ~ “(\|%3E)” ) {
set $args “”;
rewrite ^.*$ http://host/index.php last;
return 403;
}
if ( $args ~ “GLOBALS(=|\[|\%[0-9A-Z]{0,2})” ) {
set $args “”;
rewrite ^.*$ http://host/index.php last;
return 403;
}
if ( $args ~ “_REQUEST(=|\[|\%[0-9A-Z]{0,2})” ) {
set $args “”;
rewrite ^.*$ http://host/index.php last;
return 403;
}
兄弟joomla的nginx 规则有进展吗?全国人民都在等待你胜利的消息。
joomla的nginx重写网上就有,你可以参照这篇http://www.jefflei.com/post/1417.html
Fantastic thank you. Find the files I are looking for!
回复留言
水水语录
新年新人新事新内裤,过新年穿新衣服喽
最新日志
分类列表
文章归档
关键词
Apache 媳妇 PHP技术 感慨 配置 PHP类 css Memcache MySQL 调优 优化 陈陈 迪拜 生活 Linux PHP MySQL优化 Discuz! MooPHP框架 缓存 Rewrite Nginx JavaScript FireFox blog程序 MySQL效率 WordPress插件 风骚 负载 视频 生日 WordPress ZIP yy 服务器 高负载 性能 IE6 正则表达式 常用 IE7 风格 Cookie 安全 防盗链