django python

How to setup Django server

Hi fellow programers!

Few days back I decided to face my fear 😛 gathered enough courage to setup a website using django+nginx+uwsgi and I was ready to go any extent to finish this task which I have never done.


Day1(Yep it took me multiple days 😂 )

My understanding of whole nginx and uwsgi setup was next to none & most of this bit sounds me like some sort of harry potter magic…. Uwsgi sockets, Enabled-sites, Available-sites, static file hosting with django… bla bla bla… yada yada yada…

Starting few steps were relatively easier(and I was already thinking that this must not be HARD).

Installing nginx

sudo apt-get update

sudo apt-get install nginx

Installing uwsgi:

pip install uwsgi


After these two steps were done, I thought of starting nginx


sudo service nginx start

And BAM!

Nginx welcome page was already there! 😍


Things were looking so simple I thought I would go to bed only after setting this up but as every developer know there is always an issue… (stupid mistake, misread or overconfidence to name few) waiting for you when you are on the verge to completing your task on time :p and out of nowhere if jumps on right in middle and bites you… and boy it bites you read hard :joy:


For me it was understanding of following flow

( Web Client)<—–>Nginx(Web server)<——->(uwsgi_socket)<————->uwsgi<———->(Dango Application.)


This simple looking setup got me real bad.. I thought Hmm… this is easier than I thought 😛 (it was not!)

These are the few tutorial I have been following for setting up django on my aws linux VM


If you just want straight  forward tutorial for setting up django above link is a very good resource!

Don’t waste your time reading my blog… but on the other hand if you are enjoying my painful journey.. Keep on reading it’s going to get worst :joy:


Most of the tutorial i came across was telling me that it’s simple once you have uwsgi install… you don’t need to do much to see your code running just run regular


python runserver

& if that’s works

uwsgi –http :8080 –home /home/user/Env/firstsite –chdir /home/user/firstsite -w firstsite.wsgi


But in my case either of them didn’t work as i expected. I was trying to do following setup

the web client <-> uWSGI <-> Django

It cost me another frustrating day to find out this issue was because of AWS setting where TCP connection over port 8000 was not open and the very request which my browser was making was not getting register by the VM.


After bit of googling I was able to change settings in AWS so that request over port 8000 is transferred to the VM. I thought that’s it! I got it… but it was only working on running command

python runsever

Uwsgi was not serving properly even


my setup should just work with nginx as well. 🙂

But i was wrong again….

Took another half day to understand that depending on kind of way you setup uwsgi one might have to add following in uwsgi setting (sitename.ini) file.



And that was it. Everything started up and running as expected (it was actually not). This blog is in fact incomplete it’s been long I have done this setup and I don’t remember much of it now.

I will try to update it as I work on next setup in near future. 🙈