全球主机交流论坛

标题: Nginx 在 Discuz 下的 Rewrite 偽靜態配置 [打印本页]

作者: bluesky    时间: 2009-6-23 20:57
标题: Nginx 在 Discuz 下的 Rewrite 偽靜態配置
複製以下代碼 ( 哪位大俠看一下,使用後似乎不生效 )

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;
}
}
作者: cpuer    时间: 2009-6-23 21:14
http://www.ccvita.com/ 是你网站?

重写代码:

location / {
index index.html index.htm index.php;
root /路径;
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;
}

添加到对应的server下即可。

演示:http://test.daigou.in/discuz/
作者: freebsd    时间: 2009-6-23 21:28
放在server段看看
作者: bluesky    时间: 2009-6-23 21:36
那不是我的站,原文copy
如果是在bbs文件夾下
這樣對吧?
location / {
index index.html index.htm index.php;
root /bbs;
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;
}
作者: freebsd    时间: 2009-6-23 21:39
server
        {
                listen 要对外服务的IP:80;
                listen 127.0.0.1:80;  ### 用于https反向代理映射,提供网站https支持
                server_name 网站域名;
                index index.html index.htm index.php;
                root 网站目录;

                #bbs rewrite
                        rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$   /archiver/index.php?$1 last;
                        rewrite ^/forum-([0-9]+)-([0-9]+)\.html$   /forumdisplay.php?fid=$1&page=$2 last;
                        rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$  /viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last;
                        rewrite ^/profile-(username|uid)-(.+)\.html$ /viewpro.php?$1=$2 last;
                        rewrite ^/space-(username|uid)-(.+)\.html$   /space.php?$1=$2 last;
                        rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
                        break;

                #error
                        error_page 404 /error/404.html;

                #support php
                        location ~ .*\.php?$
                        {
                           include fcgi.conf;      
                           fastcgi_pass  127.0.0.1:10080;
                           fastcgi_index index.php;
                        }

                location /templates   ### 避免模板被偷
                {
                        deny all;
                }
                location ~ .*\.(gif|GIF|jpg|JPG|png|PNG|swf|SWF|css|CSS|js|JS|ico|ICO)?$   ### 不记录图像文件日志,减少日志大小
                {
                        access_log off;
                }
                log_format 日志自定义格式 '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$request_length" "$http_referer" '
                        '"$http_user_agent" $http_x_forwarded_for';
                access_log 日志文件 日志自定义格式;
        }


这是我论坛的配置。
作者: cpuer    时间: 2009-6-23 21:40
标题: 回复 4# 的帖子
如果你的是直接在 /bbs下的话是对的,路径要写全。
作者: bluesky    时间: 2009-6-23 21:42
哇 ..好詳細 ...感謝 freebsd 大俠指導
作者: zyypp    时间: 2009-6-23 22:38
标题: 回复 1# 的帖子
这份配置是网上贴的吧 我记得 以前好想见到过 那个域名 呵呵
看着C老大写的 应该是正确的 呵呵 你可以试试

server
  {
    listen       80;
    server_name  域名;
    index index.html index.htm index.php;
    root  网站路径;
    rewrite 字段
  }
作者: miyug    时间: 2009-6-23 22:56
  1. location / {                                                               
  2.                 rewrite ^(.*)/archiver/((fid|tid)-[w-]+.html)$ $1/archiver/index.php?$2 last;
  3. rewrite ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3 last;
  4. rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last;
  5. rewrite ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3 last;
  6. rewrite ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3 last;                       
  7. rewrite ^(.*)/tag-(.+).html$ $1/tag.php?name=$2 last;                              
  8.                                                                                                             
  9.         }               
复制代码
这是我现在用着的,开启伪静态使用完全没问题
作者: bluesky    时间: 2009-6-24 08:23
經過一番折騰 ... 終於完成人生第一個 Nginx 偽靜態了

http://bluesky101.twbbs.org/bbs/

最低處理時間 Processed in 0.003098 second(s)
這台爛爛的雙核主機,效率比4核心強,好奇怪?

發現一個問題 ... 底下的系統時區不正確

Nginx 偽靜態,要在 hypervm 重啟動才能生效,有沒有平滑重啟法?
作者: cpuer    时间: 2009-6-24 08:38
标题: 回复 10# 的帖子
重启nginx也可以生效的。
作者: cpuer    时间: 2009-6-24 08:40
标题: 回复 10# 的帖子
VPS的时间不受你掌控,你最好跟VPS提供商管理员反馈下,让他们更新下时间了。
作者: bluesky    时间: 2009-6-24 08:49
原帖由 cpuer 于 2009-6-24 08:40 发表
VPS的时间不受你掌控,你最好跟VPS提供商管理员反馈下,让他们更新下时间了。

突然想到 hypervm 可以設定
作者: cpuer    时间: 2009-6-24 08:53
标题: 回复 13# 的帖子
没用的,重启下就又变了,还是联系管理员更新下node时间好。
作者: bluesky    时间: 2009-6-24 09:00
真的無效耶...kloxo就可以
作者: cpuer    时间: 2009-6-24 09:04
标题: 回复 15# 的帖子
   
作者: zyypp    时间: 2009-6-24 09:35
标题: 回复 11# 的帖子
重启多没意思啊 nginx 支持平滑更新的
/nginx/sbin/nginx -t                          检测nginx.conf是否有错
kill -HUP `cat /nginx/nginx.pid`        平滑重启nginx(直接更新配置不用重启的)
作者: cpuer    时间: 2009-6-24 09:37
标题: 回复 17# 的帖子
忘记这茬了,
作者: zyypp    时间: 2009-6-24 09:43
标题: 回复 18# 的帖子
(*^__^*) 嘻嘻……

作者: cpuer    时间: 2009-6-24 10:40
标题: 回复 19# 的帖子
问下,你现在VPS用的32位还是64位系统?
作者: zyypp    时间: 2009-6-24 11:42
标题: 回复 20# 的帖子
还是用的32位的 64位的 有好多东西都要重新整 也就懒得换了 再说32位的 应用多些 呵呵
作者: cpuer    时间: 2009-6-24 11:54
标题: 回复 21# 的帖子
还以为你玩64了呢,
作者: zyypp    时间: 2009-6-24 11:58
标题: 回复 22# 的帖子
我个人感觉 64还不成熟 再说 如果是自己的设备 我还会考虑64位的 可是用的vps 我暂时不会考虑 毕竟性能在那放着呢 呵呵
作者: bluesky    时间: 2009-6-24 12:00
原帖由 zyypp 于 2009-6-24 09:35 发表
重启多没意思啊 nginx 支持平滑更新的
/nginx/sbin/nginx -t                          检测nginx.conf是否有错
kill -HUP `cat /nginx/nginx.pid`        平滑重启nginx(直接更新配置不用重启的) ...

平滑重啟 ... 讚
3Q
作者: zyypp    时间: 2009-6-24 12:10
标题: 回复 24# 的帖子

作者: cpuer    时间: 2009-6-24 18:00
标题: 回复 25# 的帖子

作者: mitmax    时间: 2009-8-27 16:22
请问这个怎么写伪静态
http://www.test.cn/index.do?hod=finnfo&skip=info&id=822
作者: cpuer    时间: 2009-8-27 16:45
标题: 回复 27# 的帖子
这个是什么程序?
作者: mitmax    时间: 2009-8-28 12:18
java 的再nginx怎么重写
作者: cpuer    时间: 2009-8-28 12:23
标题: 回复 29# 的帖子
java的是什么程序哦,不大清楚了。
作者: mitmax    时间: 2009-8-28 12:50
晕死就是把这样的链接写成伪静态就可以了 呵呵 管他什么程序
http://www.test.cn/index.do?hod=finnfo&skip=info&id=822
作者: cpuer    时间: 2009-8-28 12:55
标题: 回复 31# 的帖子
那也得有个从某动态地址到某静态地址,你这没有目标地址。
作者: mitmax    时间: 2009-8-28 13:30
http://www.test.cn/index.do?hod=finnfo&skip=info&id=822

http://www.test.cn/822.thml 或者别的
作者: cpuer    时间: 2009-8-28 13:36
原帖由 mitmax 于 2009-8-28 13:30 发表
http://www.test.cn/index.do?hod=finnfo&skip=info&id=822

http://www.test.cn/822.thml 或者别的


让GDTV帮你看下这个,我不懂正则表达式。
作者: gdtv    时间: 2009-8-28 14:00
标题: 回复 31# 的帖子
rewrite ^/findex.do?hod=finnfo&skip=info&id=([0-9]+)$  /$1\.html last;

这样?
作者: cpuer    时间: 2009-8-28 14:10
标题: 回复 35# 的帖子
大体上看起来是的,模子没错
作者: mitmax    时间: 2009-8-28 14:19
我测测看
作者: cpuer    时间: 2009-8-28 14:23
标题: 回复 37# 的帖子
  
作者: mitmax    时间: 2009-8-28 14:36
失败
作者: mitmax    时间: 2009-8-28 14:37
还行显示.do呵呵
作者: cpuer    时间: 2009-8-28 14:42
标题: 回复 40# 的帖子
显示.do是啥意思?
作者: gdtv    时间: 2009-8-28 14:52
原帖由 mitmax 于 2009-8-28 14:37 发表
还行显示.do呵呵

It Works!
作者: cpuer    时间: 2009-8-28 15:27
标题: 回复 42# 的帖子
哦哦,那就OK了。
作者: mitmax    时间: 2009-8-28 16:42
http://www.test.cn/index.do?hod=finnfo&skip=info&id=822


index.do 反正隐藏或者用html显示就可以!
LZ给个QQ这样联系太吃力了!呵呵我的 495274470
作者: mitmax    时间: 2009-8-29 09:45
楼主!!! 听到求救不
作者: mitmax    时间: 2009-8-29 09:48
原帖由 cpuer 于 2009-8-28 15:27 发表
哦哦,那就OK了。

那不是OK 我打错了 是还是显示index.do 不是显示index.html




欢迎光临 全球主机交流论坛 (https://fd.vvwvv.eu.org/) Powered by Discuz! X3.4