Question

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;
  }

}

Was it helpful?

Solution

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top