全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

IP归属甄别会员请立即修改密码
查看: 12411|回复: 45
打印 上一主题 下一主题

Nginx 在 Discuz 下的 Rewrite 偽靜態配置

[复制链接]
跳转到指定楼层
1#
发表于 2009-6-23 20:57:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
複製以下代碼 ( 哪位大俠看一下,使用後似乎不生效 )

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;
}
}
2#
发表于 2009-6-23 21:14:06 | 只看该作者
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/
3#
发表于 2009-6-23 21:28:40 | 只看该作者
放在server段看看
4#
 楼主| 发表于 2009-6-23 21:36:05 | 只看该作者
那不是我的站,原文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;
}
5#
发表于 2009-6-23 21:39:38 | 只看该作者
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 日志文件 日志自定义格式;
        }


这是我论坛的配置。

评分

参与人数 1威望 +30 收起 理由
cpuer + 30 精品文章

查看全部评分

6#
发表于 2009-6-23 21:40:19 | 只看该作者

回复 4# 的帖子

如果你的是直接在 /bbs下的话是对的,路径要写全。
7#
 楼主| 发表于 2009-6-23 21:42:30 | 只看该作者
哇 ..好詳細 ...感謝 freebsd 大俠指導
8#
发表于 2009-6-23 22:38:45 | 只看该作者

回复 1# 的帖子

这份配置是网上贴的吧 我记得 以前好想见到过 那个域名 呵呵
看着C老大写的 应该是正确的 呵呵 你可以试试

server
  {
    listen       80;
    server_name  域名;
    index index.html index.htm index.php;
    root  网站路径;
    rewrite 字段
  }
9#
发表于 2009-6-23 22:56:31 | 只看该作者
  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.         }               
复制代码
这是我现在用着的,开启伪静态使用完全没问题

评分

参与人数 1威望 +30 收起 理由
cpuer + 30 精品文章

查看全部评分

10#
 楼主| 发表于 2009-6-24 08:23:01 | 只看该作者
經過一番折騰 ... 終於完成人生第一個 Nginx 偽靜態了

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

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

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

Nginx 偽靜態,要在 hypervm 重啟動才能生效,有沒有平滑重啟法?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-11-11 20:00 , Processed in 0.080225 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表