By bnkamalesh
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?
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!
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>
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.