【问题标题】:Rewrite rule for nginx?重写nginx的规则?
【发布时间】:2015-10-13 12:22:16
【问题描述】:

我正在尝试使用 nginx 部署 trac。除了提供静态文件的重写规则外,我几乎已经完成了所有工作。我需要重写这个网址:

http://trac.domain.tldn/chrome/common/feed.png

到这个:

http://trac.domain.tldn/static/htdocs/common/feed.png

我有这个代码,但它不起作用:

    location ~ /(.*?)/chrome/common/ {
            rewrite /(.*?)/chrome/common/(.*) /$1/static/htdocs/common/$2 break;
            root    /var/www/domain.tldn/static/trac/static/htdocs/common;
    }

你能帮我解决这个问题吗?

【问题讨论】:

  • Trac Nginx 文档需要改进,尤其是serving static files。我希望尽快重写,但@dmitriy-z 的答案看起来是正确的。

标签: nginx url-rewriting trac static-files


【解决方案1】:

您可以使用以下代码:

location /chrome/common {
    rewrite ^/chrome/common/(.*) /static/htdocs/common/$1 permanent;
}

或者只是为您的文件路径使用别名:

location /chrome/common {
    alias /var/www/domain.tldn/static/trac/static/htdocs/common;
}

【讨论】:

  • 根据您是否安装了插件和特定于站点的模板,Trac 还可以提供来自/chrome/<plugin>/chrome/site 的文件,因此您可能只想在location 中使用/chrome/指令并从alias 指令中剥离/common
猜你喜欢
  • 2010-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-05
  • 1970-01-01
  • 2015-03-04
  • 2013-10-12
相关资源
最近更新 更多