VPS侦探论坛

 找回密码
 注册
查看: 7104|回复: 2

LNMP1.1下rewrite规则变更问题

[复制链接]
发表于 2014-6-26 21:57:05 | 显示全部楼层 |阅读模式

关注和使用LNMP一年多,受益匪浅,在此感谢军哥!刚刚升级到了1.1版本,遇到一个不大不小的问题。和之前1.0版本使用一样的rewrite规则(添加域名的时候选择discuz什么的,这个文件位于/usr/local/nginx/conf/下),却不生效。具体如下:

  1. location / {
  2. rewrite "^.+dl/?(.*)[        DISCUZ_CODE_0        ]quot; http://dl.wifihell.com/$1 permanent;
  3. rewrite "^.+forum/?(.*)[        DISCUZ_CODE_0        ]quot; http://forum.wifihell.com/$1 permanent;
  4. rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
  5. rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
  6. rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
  7. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
  8. rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
  9. rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
  10. rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
  11. rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
  12. rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
  13. if (!-e $request_filename)

  14. {
  15.         return 404;
  16. }

  17.         }
复制代码


第二行规则的本意是把http://www.wifihell.com/dl/csc.png的URL改为http://dl.wifihell.com/
csc.png。此规则在1.0版本是完全可用的。经测试,扩展名为png、jpg、swf都不可能用,于是想到了对比前后生成的conf文件,也一样的。不过这个时候发现了一个规律,在conf文件内有一段

  1. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  2.                         {
  3.                                 expires      30d;
  4.                         }
复制代码



一不做二不休,改为

  1. location ~ .*\.(aa)$
  2.                         {
  3.                                 expires      30d;
  4.                         }
复制代码


这个时候跳转就正常了。因为有的图片链接是以前输入的,没心思一个一个去找来修改,就只有用这个办法。希望对遇到此问题的人有帮助,另外希望军哥给出一个更加详细的rewrite规则介绍,虽然能Google到不少,但是对于lnmp的实际应用意义不大。

[ 本帖最后由 wifihell 于 2014-6-26 21:59 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2014-6-27 10:36:12 | 显示全部楼层


有时候图片的缓存可能会影响个别程序的伪静态

为适应pathinfo php的解析进行了一下调整
可以将location ~ [^/]\.php(/|$)替换为原来的location ~ .*\.(php|php5)?$ 试试看
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2014-7-1 00:05:15 | 显示全部楼层

回复 2# 的帖子


后期仔细对比了一下,以前的配置文件是直接把“”location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$“”段注释了,等于说和帖子中指出的内容没有直接关系。  。遇到这个问题的人可以借鉴。
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-25 21:20 , Processed in 0.025892 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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