0

I have nginx running as my main web server but I also have a tornado server running https at 127.0.0.1:8888 (same machine as the nginx server). I would like to redirect traffic to my tornado server when a user goes to http://myserver.com/tornadoapp. I have this so far...

# tornado server
upstream tornadoserver {
        server 127.0.0.1:8888;
}

server {
        listen  80 default_server;
        root    /var/www;
        location /tornadoapp {
                proxy_pass https://tornadoserver;
        }
}

It actually does forward the request to my tornado server app, but tornado generates this error...

WARNING:tornado.access:404 GET /tornadoapp (127.0.0.1) 1.75ms

So the redirect is going to tornado but I'm getting an error because tornado does not have a handler for /tornadoapp. It has handlers for /, /login, and /user, etc... I was hoping to use http://myserver.com/tornadoapp as an "alias" or mask so that the URL looks seamless to the end user (no port numbers), that way...

# When this is typed
http://myserver.com/tornadoapp/login

# they are directed here...
https://localhost:8888/login  

without the url showing the port number. Is there a way to do this? I've looked over a few examples online but most seem to deal with https redirects to other domains or using / as the location in the server block. None of them seem to cover this exact problem. If this is not possible or I'm way off in my approach please let me know. I'm fairly new to nginx so any help would be appreciated. Thanks!

Itai Ganot
  • 10,424
  • 27
  • 88
  • 143
b10hazard
  • 101
  • 1
  • 2

1 Answers1

1

Add a trailing / to your proxy_pass line so it looks like this:

proxy_pass https://tornadoserver/;

This should cause nginx to strip the location part of the URI (in your case /tornadoapp) before passing it to tornado.

Also see the documentation: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

jhenninger
  • 111
  • 2