I’m quite new to backend and servers configurations.
I have a Django website already running using Nginx and Gunicorn and is successfully deployed to my Droplet.
I’m deciding to host multiple websites including test apps of different sorts i.e PHP, Wordpress, Laravel, Java supported backends, on the current droplet. But I don’t know exactly how to do it. I have some rough knowledge of Nginx Blocks. However I cannot dare to experiment with it because I’m afraid if something goes wrong my current running website would go down.
I don’t know how to do it? Will it affect my current website? How can I separate my current active website form all other process running in my Droplet?
Any help will be appreciated and also I would love to refer me to some tutorials and references so I can achieve what I want.
Note: I’m running Ubuntu 18.04 on my 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!
Hello,
As you already have Nginx installed, what you could do is to use separate Nginx Server Blocks for each of your websites.
You can follow the steps here on how to do that:
For PHP you could follow the steps here on how to install it on your server, you can skip the Nginx installation step as you already have this installed:
Hope that this helps. Regards, Bobby
Configuring multiple Django projects on a single DigitalOcean droplet using Nginx as a reverse proxy involves several key steps, including setting up Nginx server blocks (similar to virtual hosts in Apache) and managing Django project settings for production. Here’s a comprehensive step-by-step guide on how to do this:
Create a Droplet: If you haven’t already, create a DigitalOcean Droplet with a Linux distribution like Ubuntu.
SSH into your Droplet:
bashCopy code
ssh root@your_droplet_ip
Update your system:
bashCopy code
sudo apt update && sudo apt upgrade
sudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx curl git
sudo apt install python3-venv
For each Django project:
mkdir /var/www/project1 cd /var/www/project1
python3 -m venv venv source venv/bin/activate
requirements.txt):pip install django gunicorn psycopg2-binary
Configure your Django project settings to connect to the database and manage static and media files correctly.
Collect static files:
python manage.py collectstatic
project1:sudo nano /etc/systemd/system/project1_gunicorn.service
Add the following configuration:
[Unit]
Description=gunicorn daemon for project1
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/project1
ExecStart=/var/www/project1/venv/bin/gunicorn --workers 3 --bind unix:/var/www/project1/project1.sock project1.wsgi:application
[Install]
WantedBy=multi-user.target
Start and enable the service:
sudo systemctl start project1_gunicorn
sudo systemctl enable project1_gunicorn
sudo nano /etc/nginx/sites-available/project1
Example configuration for project1:
server {
listen 80;
server_name project1.domain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /var/www/project1;
}
location / {
include proxy_params;
proxy_pass http://unix:/var/www/project1/project1.sock;
}
}
Enable the Nginx server block by linking it to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/project1 /etc/nginx/sites-enabled
sudo nginx -t
sudo systemctl restart nginx
sudo ufw allow 'Nginx Full'
sudo ufw allow ssh
sudo ufw enable
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d project1.domain.com
By following these steps, you can efficiently run multiple Django projects on a single DigitalOcean droplet, each accessible via its unique domain and securely handled by Nginx as a reverse proxy.
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.