Location / rewrite help needed

Igor Sysoev igor at sysoev.ru
Thu Dec 3 11:18:10 MSK 2009


On Thu, Dec 03, 2009 at 03:10:48AM -0500, saile wrote:

> Hi,
> 
> let's say I use upstream to push the requests to Rails for example like this:
> 
> 
> upstream thin {
>     server 127.0.0.1:8000;
>     server 127.0.0.1:8001;
>     server 127.0.0.1:8002;
> }
> 
> server {
> 	listen   80;
> 	server_name  localhost;
> 	access_log  /var/log/nginx/localhost.access.log;
> 	root /var/www/test/public;
> 	
> 	location / {
> 		proxy_set_header  X-Real-IP  $remote_addr;
> 		proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
> 		proxy_set_header Host $http_host;
> 		proxy_redirect false;
> 		if (-f $request_filename/index.html) {
> 		        rewrite (.*) $1/index.html break;
> 		}
> 		if (-f $request_filename.html) {
> 		        rewrite (.*) $1.html break;
> 		}
> 		 if (!-f $request_filename) {
> 		        proxy_pass http://thin;
> 		        break;
> 		}
> 	}
> }
> 
> 
> 
> Is it possible to define a second location which not should redirect the request to the upstream but instead redirect to a folder with static files in it?
> 
> How would you do that?

      location / {
          try_files  $uri/index.html  $uri.html  $uri  @thin;
      }

      location /folder/ {
          root  ...
      }

      location @thin {
          proxy_pass http://thin;
          proxy_set_header  X-Real-IP  $remote_addr;
          proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
      }


-- 
Igor Sysoev
http://sysoev.ru/en/




More information about the nginx mailing list