By aminbandali
So, I have a Django droplet and I’ve pointed a subdomain (say django.example.com) to the ip address of my droplet.
Then, I installed ghost on the same droplet and now I want to have blog.example.com load my ghost installation. I followed this tutorial but when I opened blog.example.com, instead of ghost, django showed up.
So, can you please help me with setting up multiple "server"s on subdomains on Nginx on a droplet?
Thanks!
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!
@amin.bandali And your blog is dead? It was better if you added the ‘small gotchas’ here instead.
The key to setting up multiple websites on different domains or subdomains on the same server is setting up server_name in your server blocks. So your Ghost configuration would look something like:
server {
listen 0.0.0.0:80;
server_name blog.example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:2368;
proxy_redirect off;
}
}
And your Django configuration would be like:
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name django.example.com;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/django_project/django_project/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/django_project/django_project/static;
}
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;
}
}
And of course, remember to restart Nginx after making your changes:
sudo service nginx restart
Hello there,
You can host multiple sites (domain names) on a single droplet, this can be achieved using virtual hosts.
The process is really simple, all you need to do is to spin up the droplet via the app marketplace and then manually add the virtual hosts for the other sites.
We have an article that covers the process, which you check here:
Hope that this helps! Regards, Alex
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.