【问题标题】:nginx ignoring Apache rewrite directivenginx 忽略 Apache 重写指令
【发布时间】:2011-08-23 08:37:01
【问题描述】:

我的问题是这样的: - 我现在在 Apache 服务器前使用 nginx,这意味着我所有的网站 - 我在 .htaccess 文件中的所有重写工作都很完美,除了 1 及以上到目前为止没有人设法给我一个解决方案

这是 .htaccess 规则

 -------------
    RewriteCond %{THE_REQUEST} ^.*/index\.(html|htm)\ HTTP/
    RewriteRule ^(.*)index\.(html|htm)$ http://%{HTTP_HOST}/$1 [R=301,L]
 -------------

这将执行以下操作: - 它使用 301 http 代码从 www.domain.com/index.html 重定向到 www.domain.com - 它需要 index.html 和 index.htm

现在的问题是,这在安装 nginx 之前有效,并且到目前为止适用于 index.htm.. 它可以正确重定向。 但 index.htm 不存在。

我尝试了相反的方法,发现如果文件存在,重定向不会发生。

我发现的另一件奇怪的事情如下:我还从 Google 安装了 mod_pagespeed,当我使用 www.domain.com/index.html 访问 URL 时...不会重写到 / 的那个 mod_pagespeed is... inactive.. 意味着例如源中没有发生任何变化....就像那个 URL 不是来自相同的正常请求。

Btw..in ssh 当我发出 nginx 命令时,我得到了这个:

nginx: [warn] duplicate MIME type "text/html" in /etc/nginx/nginx.conf:30
nginx: [emerg] bind() to 111.111.111.111:80 failed (98: Address already in use)
nginx: [emerg] bind() to 111.111.111.111:80 failed (98: Address already in use)
nginx: [emerg] bind() to 111.111.111.111:80 failed (98: Address already in use)
nginx: [emerg] bind() to 111.111.111.111:80 failed (98: Address already in use)
nginx: [emerg] bind() to 111.111.111.111:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

111.111.111.111 - 假ip

我已经查找了重复的 MIME.. 在那里找不到它,其余的绑定内容... 一点头绪都没有。

如果你们有任何线索,我很乐意与你们分享一杯虚拟啤酒,以获得很好的信息。

谢谢

【问题讨论】:

  • 首先,nginx 尝试监听 apache 已经使用的 80 端口。如果您希望 nginx 成为前端,您应该将 apache 移动到另一个端口。
  • 感谢您的提示 :) 我如何在不破坏内容的情况下做到这一点?编辑 httpd.conf?我知道那里有港口。
  • 然而,以上是优先级列表中最少的。我更关心的是重定向没有做它应该做的事情。
  • 我不明白你为什么需要RewriteCond。看起来 RewriteRule 一个人就可以完成这项工作。
  • 访问 www.domain.com/index.html 时遇到什么错误?在apache的日志中?在浏览器中?

标签: apache redirect nginx rewrite


【解决方案1】:

这可能会有所帮助。

RewriteCond %{THE_REQUEST} ^.*/index\.(html|htm)\ HTTP/ [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)index\.(html|htm)$ http://%{HTTP_HOST}/$1 [R=301,L]

【讨论】:

  • nope :( 就像那个 URL .. 完全忽略 .htaccess 。如果我在 .htaccess 中写了一些错误的行并访问该 URL,则会显示该文件.. 如果我检查其他 URL,它们会失败502 就像他们应该的那样:|
猜你喜欢
  • 2010-10-27
  • 2013-05-30
  • 2012-01-30
  • 2013-09-27
  • 2021-12-04
  • 1970-01-01
  • 1970-01-01
  • 2012-01-29
  • 2019-12-31
相关资源
最近更新 更多