Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidofug/c6b8eb6e072a769c3aaf5722117ade1e to your computer and use it in GitHub Desktop.
Save davidofug/c6b8eb6e072a769c3aaf5722117ade1e to your computer and use it in GitHub Desktop.
Code Step-by-Step Guide on Connecting Your Django App to a Custom Domain Name.
# 1. Navigate to the Nginx server directive directory.
cd /etc/nginx/conf.d/
or
/etc/nginx/sites-available/
# 2. Create a the Server block configuration file.
sudo nano domain.com.conf
# 3. Add configuration code to the configuration file and save.
# This is a comment
server {
# Listen on port 80
listen 80;
# Server name
server_name domain.com;
location / {
# Proxy pass to Django server on localhost:8000
proxy_pass http://127.0.0.1:8000;
# Set headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 4. Test the configuration
sudo nginx -t
# 5. If all is good, restart the nginx service
sudo systemctl restart nginx
or
sudo service nginx restart
# well done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment