NginxHttpMapModule

Goldcap nginx-forum at nginx.us
Fri Oct 16 01:34:46 MSD 2009


I'm unclear how to mimic the Apache rewrite map using the NginxHttpMapModule.

I've included a map in my nginx.conf file, as so:

===================================
map $uri $new {
  default        http://www.domain.com/home/;
 
  /aa            http://aa.domain.com/;
  /bb            http://bb.domain.com/;
  /john          http://my.domain.com/users/john/;
}
===================================

Then have trouble using the map without excuding all other rules in my server configuration. The following rewrites everything, obviously, but couldn't figure out how to get a conditional match wrapped around it or from it:

===================================
server {
  listen       80;
  server_name some.domain.com;
  rewrite  ^    $new   redirect;

  root /var/www/web;
  index  index.php;
  
  access_log  /var/log/httpd/nginx_access_log main;
  error_log  /var/log/httpd/nginx_error_log;

  charset utf-8;
  
  location / {
    
    # If the file exists as a static file serve it directly without
    # running all the other rewite tests on it
    if (-f $request_filename) {
      expires max;
      break;
    }
    
    if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") {
      rewrite ^(.*) /index.html last;
    }
  }
===================================

I'm obviously missing something, but how would one wrap this Map conditionally? If no "map" rules trigger, continue with "locations'...

Is this possible?

Thanks in advance!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,14117,14117#msg-14117






More information about the nginx mailing list