two domains can work on two django projects in one droplet
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!
Hi @hayitmurod3933,
In order to have more than one Django app listening on port 80, you’ll need to allow Nginx to direct requests to the correct app. You’ll also need to set up DNS records. By setting the server_name directive in each of your server blocks, Nginx will know what to serve.
Here’s a simplified example:
upstream app_server_one {
server 127.0.0.1:9000 fail_timeout=0;
}
upstream app_server_two {
server 127.0.0.1:7000 fail_timeout=0;
}
server {
listen 80 default_server;
server_name: example.com;
root /var/www//html;
index index.html index.htm;
# [snip...]
}
server {
listen 80;
server_name app1.example.com;
# [snip...]
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server_one;
}
}
server {
listen 80;
server_name app2.example.com;
# [snip...]
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server_two;
}
}
In the example, requests to example.com will serve static content from /var/www//html One to app1.example.com will serve a Django app listening on port 9000 and app2.example.com will serve the app listening on port 7000.
You can get more info on how to use Nginx server block in this tutorial:
And on using Django with Nginx:
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.