Poetry of Programming

Its about Ruby on Rails – Kiran Soumya

By

Redirect Address/Path with Nginx

Here is the nginx config file which redirects

http://mysite/escapeme/blah =>  http://mysite:3000/blah

user www-data;
worker_processes  3;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
 worker_connections  1024;
}
http {
 include     /etc/nginx/mime.types;
 access_log  /var/log/nginx_access.log;
 sendfile        on;
 keepalive_timeout  65;
 tcp_nodelay        on;
 server {
 listen   *:80; ## listen for ipv4
 access_log  /var/log/nginx_access.log;
 location /escapeme {
 rewrite /escapeme(.*) $1 break;
 proxy_pass http://127.0.0.1:3000;
 proxy_redirect     off;
 proxy_set_header   Host             $host;
 proxy_set_header   X-Real-IP        $remote_addr;
 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
 }
 }
}

2 Responses to Redirect Address/Path with Nginx

  1. Ashish Prasad says:

    Nice one Kiran ! and that was quick !! :)

Leave a Reply

Your email address will not be published. Required fields are marked *