【问题标题】:How to convert this Apache RewriteRule in Nginx?如何在 Nginx 中转换这个 Apache RewriteRule?
【发布时间】:2014-06-11 07:10:16
【问题描述】:

我有这个 RewriteRule,但我不能让它与 nginx 一起工作:

RewriteRule  ^/espace-annonceurs/@@contenu-des-espaces-annonceurs http://mywebsite.com/@@contenu-des-espaces-annonceurs [L,P]

Proxy 是因为它发出 ajax 请求。

我尝试了很多东西,位置、proxy_pass、重写等等......

提前致谢。

【问题讨论】:

  • @@contenu-des-espaces-annonceurs 是一个目录还是一个页面? @@ 有什么特别的意义吗?
  • 它只是一个页面,@@ 表示它是 CMS 的视图,所以,它并不重要。

标签: apache mod-rewrite nginx reverse-proxy


【解决方案1】:

实际上,您需要将主机请求代理到其他主机。这是代理模块的工作。最简单的配置是这样的:

location /espace-annonceurs/@@contenu-des-espaces-annonceurs {
    proxy_pass http://mywebsite.com/@@contenu-des-espaces-annonceurs;
}

您可能需要一些proxy_set_headers 指令。

阅读文档http://nginx.org/r/proxy_pass

【讨论】:

  • 谢谢,我会看看这个,特别是proxy_set_header
【解决方案2】:

所以一个简单的重写就可以了。

rewrite ^/(espace-annonceurs/@@contenu-des-espaces-annonceurs)$ http://example.com/$1;

【讨论】:

  • 是的,但是由于跨域,这不起作用,这就是为什么我们在 apache 上有一个代理模块。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-10
  • 2020-09-22
  • 2013-01-23
  • 1970-01-01
  • 2014-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多