Hello I want to host 2 djagno websites using Gunicorn and Nginx and I don't know how to do this this is my first time to host 2 django websites in one server and 2 domain so please tell me how to host 2 django website. Here is my 1 file located /var/www/site1 and here is my 2 file /var/www/site2
Assuming you run your gunicorn instances on ports 8081 and 8082, you have two options:
To use subdomains to reverse-proxy with NGINX, see this answer.
http://site1.example.com/ redirects to Site 1 and http://site2.example.com/ to Site 2.
NGINX config:
server {
listen 80;
server_name site1.example.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
server {
listen 80;
server_name site2.example.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
http://example.com/site1/ now redirects to Site 1 and http://example.com/site2/ to Site 2.
NGINX config:
server {
listen 80;
server_name example.com;
location /site1/ {
proxy_pass http://127.0.0.1:8081;
}
location /site2/ {
proxy_pass http://127.0.0.1:8082;
}
}
You can also just use different domains for the different sites just as in option 1.
http://site1.com/ redirects to Site 1 and http://site2.com/ to Site 2.
NGINX config:
server {
listen 80;
server_name site1.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
server {
listen 80;
server_name site2.com;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
Note: These are bare minimum setups and may need additional configuration to work with your specific services.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With