【问题标题】:Converting apache rewrite rules (.htaccess) to nginx将 apache 重写规则 (.htaccess) 转换为 nginx
【发布时间】:2013-01-04 21:31:21
【问题描述】:

背景:

我想在运行 nginx 的 Ubuntu 服务器上设置 Bugify。我按照说明安装了依赖项,安装成功。一旦我输入我的许可证密钥并单击“安装 Bugify”,它就会重定向到 http://dev.mysite.com/login?new,而我看到的唯一内容是 404 Not Found

我知道 nginx 不受官方支持,但根据support forum 应该可以运行它。

问题:

在 webapp 的公共目录中有一个带有重写规则的 .htaccess 文件,我猜导致 404 错误的问题是 nginx 无法使用 .htaccess 文件,所以我必须转换将规则重写为 nginx 语法。

我不太熟悉 apache 的重写规则,所以我需要一些帮助来解决这个问题。

.htaccess 文件的内容是:

# Rewriting
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

我使用this tool 来转换规则,但是- 标志出现了一些问题。

#ignored: "-" thing used or unknown variable in regex/rew

提前致谢!

【问题讨论】:

  • 转换器“忽略”的破折号表示不重写匹配请求。

标签: apache mod-rewrite nginx


【解决方案1】:

Bugify 使用 Zend 框架,因此 ZF 的重写规则也适用于 Bugify。我已经从http://wiki.nginx.org/Zend_Framework复制了下面建议的 nginx 配置

server {
  listen 80;
  server_name www.example.com;
  root /var/www/www.example.com/myapplication;
  index  index.html index.htm index.php;

  location / {
    # This is cool because no php is touched for static content
    try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    fastcgi_pass      unix:/usr/local/zend/tmp/php-fastcgi.socket;
    fastcgi_index    index.php;
    fastcgi_param   SCRIPT_FILENAME /var/www/www.example.com/myapplication$fastcgi_script_name;
    include               fastcgi_params;
  }
}

【讨论】:

  • 我使用了完全相同的 nginx 配置,除了没有 try_files $uri $uri/ /index.php; 部分。我添加了它,现在一切正常。即使没有官方支持 nginx,也感谢您的支持。如果您将此 sn-p 添加到 bugify 知识库,我想您可以将其添加到支持的网络服务器列表中!
猜你喜欢
  • 2014-06-30
  • 2016-08-09
  • 2011-04-16
  • 2021-04-04
  • 1970-01-01
  • 2016-06-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多