I have a django project. I have installed nginx server. I want to run nginx along with django on windows machine. I have tried a few blogs Nginx Django Uwsgi. But all of them required uwsgi. But the uwsgi is not installing on windows and gives "uname" error. Is there any way to install and run nginx and django on windows ? Any pointers will be very helpfull thanks.
It takes you through the steps required to set up Django so that it works nicely with uWSGI and nginx. It covers all three components, providing a complete stack of web application and server software. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Nginx is a web server that is very popular with Linux and BSD systems. It can also be installed on Windows 10.
Django can be installed easily using pip . In the command prompt, execute the following command: pip install django . This will download and install Django. After the installation has completed, you can verify your Django installation by executing django-admin --version in the command prompt.
After the Django1.9+, the FastCGI support via the runfcgi management command is removed. So you have to use old version django, or use the mod_wsgi + apache.
If you only want to develop the django code, then you can just edit nginx.conf add proxy_pass http://127.0.0.1:8000 into the location option. For example:
location /api/ {
proxy_pass http://127.0.0.1:8000;
}
location /static/ {
proxy_pass http://127.0.0.1:8000;
}
Best way (IMHO) is using apache+mod_wsgi. Both uWSGI and Gunicorn are not windows-friendly (albeit uWSGI has cygwin support, so you can eventually try it [if you are brave enough]).
Another approach would be installing a linux vm (virtualbox, vmware...) on the windows machine to host your application and proxy requests from local IIS to the virtual system.
This question is from a year ago but I'll answer this for the others looking for a solution to their Windows Django/nginx problems.
As uWSGI is clearly not an option for Windows (forget about cygwin/virtual environments). I didn't want to go for mod_wsgi + Apache
because I had to merge an existing AngularJS/nginx project together with my newly created Django project.
I ended up using FastCGI, even though Django support for it will soon be deprecated, it still works. This (somewhat badly written but it does help) tutorial helped me with this.
The key actions were:
flup
is installed ( pip install flup
)Edit your nginx.conf as shown in the tutorial:
location / {
# host and port to fastcgi server
fastcgi_pass 127.0.0.1:<port nr>;
fastcgi_pass_header Authorization;
fastcgi_hide_header X-Accel-Redirect;
fastcgi_hide_header X-Sendfile;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PROTOCOL $server_protocol;
}
Then run your Django project with fcgi, with the port being the same one as seen above in the .conf python manage.py runfcgi method=threaded host=127.0.0.1 port=<port nr>
Worked for me.
If you don't have any reason like I had for which you really want to use nginx, I'd suggest going for the mod_wsgi + Apache
webserver approach, it will probably make your life a lot easier.
You can try to use Helicon Zoo to run Django applications on Windows machine with IIS 7+. Helicon Zoo is stable and production-ready.
Tutorial here: Running Django on Windows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With