简体   繁体   English

将Apache重写规则(.htaccess)转换为nginx

[英]Converting apache rewrite rules (.htaccess) to nginx

Background: 背景:

I want to setup Bugify on my Ubuntu Server running nginx. 我想在运行nginx的Ubuntu服务器上设置Bugify I followed the instructions, installed the dependencies and the installation was successful. 我按照说明进行操作,安装了依赖项,安装成功。 Once I enter my licence key and click on "Install Bugify" it's redirecting to http://dev.mysite.com/login?new and the only thing I'm seeing is 404 Not Found . 输入许可证密钥并单击“安装Bugify”后,它会重定向到http://dev.mysite.com/login?new ,我唯一看到的是404 Not Found

I know that nginx isn't officially supported but according to the support forum it should be possible to run it. 我知道nginx没有得到官方支持,但是根据支持论坛 ,应该可以运行它。

Question: 题:

There's a .htaccess file with rewrite rules in the webapp's public directory and I guess the problem causing the 404 error is that nginx isn't able to work with the .htaccess file, so I'll have to convert the rewrite rules to the nginx syntax. webapp的公共目录中有一个带有重写规则的.htaccess文件,我猜是导致404错误的问题是nginx无法使用.htaccess文件,因此我必须将重写规则转换为nginx句法。

I'm not really familiar with apache's rewrite rules so I'd need some help figuring this out. 我对apache的重写规则不是很熟悉,因此我需要一些帮助来解决这个问题。

The content of the .htaccess file is: .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]

I was using this tool to convert the rules but it's having some troubles with the - flags. 我当时使用此工具来转换规则,但是-标志有些麻烦。

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

Thanks in advance! 提前致谢!

Bugify uses the Zend Framework, so the rewrite rules for ZF should work for Bugify also. Bugify使用Zend框架,因此ZF的重写规则也应适用于Bugify。 I have copied the suggested nginx config below from http://wiki.nginx.org/Zend_Framework 我已经从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;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM