Apache rewrite rule to NGINX for HHVM

删除回忆录丶 提交于 2019-12-13 22:03:41

问题


We're moving from apache to NGINX and Hip Hop Virtual Machine (HHVM). I can't seem to get our rewrite rules lined up and working properly in NGINX. Here is the current working apache rule set:

RewriteEngine On RewriteBase /

    #send www.domain.com -> domain.com
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$
    RewriteRule ^(.*)$ http://domain.com%{REQUEST_URI} [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule td/api(.*) http://dp.domain.com/api$1 [P,L]
    RewriteRule ^.*$ /index.php [NC,L]
    </IfModule>

Here is what I have tried currently:

  server {
  server_name test.domain.com;
  listen 80;
  root /path/public_html;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  index       index.html index.htm index.php;

  location / {
  try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_param  SCRIPT_FILENAME /path/public_html/index.php;
  include        fastcgi_params;
  }

}


回答1:


What exactly is the problem you're encountering and which version of ZF are you using? The following config works for ZF1.12. You can test the config and debug it by calling the following command (on RHEL/CentOS):

$ service nginx configtest

You can also check the error logs:

$ tail -f /var/log/nginx/error.log

The config:

server {
    listen        80 default;
    server_name   test.domain.com;
    root          /path/public_html;
    index         index.php index.html index.htm;
    client_max_body_size 3M;

    location / {
        server_tokens off;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
        access_log        off;
        log_not_found     off;
        expires           360d;
    }

    location ~ /\.ht {
        deny all;
    }
}


来源:https://stackoverflow.com/questions/23481058/apache-rewrite-rule-to-nginx-for-hhvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!