Django application on an Nginx + cPanel Apache setup

This is how you configure an Django application on your cPanel webserver with Nginx + Apache.

Here my should be running only over httpS URL for the public,

## Steps

1. Install cPanel as normal,
2. reserve an IP for Nginx (say 1. Show/Edit Reserved IPs >> Tick the IP to use for Nginx and put a comment as Nginx >> Save
2. Apache Configuration >> Reserved IPs Editor >> Tick the IP to choose reserved >> Save
3. Park a domain in cPanel for the hosting account
4. Add /etc/hosts entry on the serve [](
5. Install Nginx
6. Disable HTTPS completely  from Django level.
7. Configure nginx to bind 80 port only.
8. vim /etc/nginx/nginx.conf [sociallocker]

user nginx; worker_processes 4; error_log /var/log/nginx/error.log warn; pid /var/run/; events { worker_connections 1024; multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘ ‘$status $body_bytes_sent “$http_referer” ‘ ‘”$http_user_agent” “$http_x_forwarded_for”‘; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 120; gzip on; gzip_buffers 16 8k; gzip_comp_level 4; gzip_http_version 1.0; gzip_min_length 1280; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp; gzip_vary on; include /etc/nginx/conf.d/*.conf; }

9. Redirect All HTTP traffic to the correct HTTPS url

[/etc/nginx/conf.d]# cat domain.conf server { listen; server_name _; rewrite ^$request_uri? permanent; }

10. Configure the site to host the site as HTTPS

[/etc/nginx/conf.d]# cat domain-ssl.conf server { listen ssl; server_name; ssl_certificate /etc/nginx/ssl/cert.pem; ssl_certificate_key /etc/nginx/ssl/ssl.key; location /static { alias /home/user/project/static; expires 10d; break; gzip on; } location /media { alias /home/user/project/media; gzip on; expires 10d; break; } location / { proxy_pass; #proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; } }


Feel Free to comment of any doubt / Issues

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
Scroll to Top