Question

Multiple domains on different ports of the same droplet.

Hello,

I’m running different apps on different ports of my droplet. Everything works fine, but I have to specify the ports explicitly in order to visit the website. How can I make a specific domain point to a specific port?

Configuration: Apps developed in Python 2.7, using Flask. Deployed on CherryPy server. Right now, there are 2 instances of CherryPy, each running different app on different ports (one, the default 80, and another on 8080).

Any help?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You could deploy Nginx in front of the CherryPy servers to act as a reverse proxy and direct traffic. Basically, you’d need to have the CherryPy servers listen on some random port on localhoast, then configure Nginx to pass requests to those ports based on domain names.

The Nginx configuration would look something like:

<pre> upstream first_server { server 127.0.0.1:3000; }

upstream second_server { server 127.0.0.1:4000; }

server { listen 80; server_name domain-one.com;

# Settings to serve static files 
location ^~ /static/  {
    # root /full/path/to/application/static/file/dir;
    root /app/static/;
}

location / {
    proxy_pass         http://firstp_server;
    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;
    proxy_set_header   X-Forwarded-Host $server_name;
}

}

server { listen 80; server_name domain-two.com;

# Settings to serve static files 
location ^~ /static/  {
    # root /full/path/to/application/static/file/dir;
    root /app/static/;
}

location / {
    proxy_pass         http://second_server;
    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;
    proxy_set_header   X-Forwarded-Host $server_name;
}

} </pre>