The WSGI module of Nginx is out of date? - python

I love python and I want to use python to construct my blog. I have deployed a nginx server and I find that in python wiki:
In addition to the above, some non-Python-based Web servers support
Python-based applications by embedding the Python virtual machine for
improved performance:
Nginx WSGI support module for Nginx HTTP server
I goto Nginx WSGI wiki page, but find:
mod_wsgi tested with Nginx 0.8.31 and python-2.6.2
My nginx version is 1.4.4(deployed one year before)...
I find a update information page in that wiki page, I click it hopefully:
Browser gives DNS look up error:ERR_NAME_NOT_RESOLVED
So, my question is:
mod_wsgi is out of date and is not good choice for python server?
If I want to use nginx as my http server, what is a better choice?
If I don't insist to use nginx, what is my best choice?

As I mentioned in my comment, the preferred way to deploy Python applications with nginx is to use it as a reverse proxy to a standalone Python WSGI server such as gunicorn or uwsgi.
The documentation for both projects includes sample configuration for running with nginx.

Related

Should you deploy django with wsgi?

Do you need to deploy django with wsgi? I am running Django on a Docker instance and it seems like often the recommended solution is just to use Django's development server, i.e. the command python manage.py runserver. When exactly is a web server such as wsgi needed -- and in this instance, in a containerized application, is the django development server enough for production applications?
You answer your own question:
is the django development server enough for production applications ?
In the django documentation, you can read the following:
Now’s a good time to note: don’t use this server in anything resembling a production environment. It’s intended only for use while developing. (We’re in the business of making Web frameworks, not Web servers.)
And also this part:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
So no. Don't use the Django development server in production. Security risks, poor performances, etc.
The development server is never recommended as an option for production server. It has a number of security and performance issues.
The solution which is working well for us is Gunicorn behind an Nginx reverse proxy (so that multiple people can connect smoothly.)
The method mentioned in this tutorial is a good beginners guide to a Ubuntu setup with nginx and gunicorn. When bringing docker into the mix use this tutorial.
You can use Django Channels to deploy in production without using WSGI.
You can set things up in one of two ways; either route all traffic through a HTTP/WebSocket interface server, removing the need to run a WSGI server at all; or, just route WebSockets and long-poll HTTP connections to the interface server, and leave other pages served by a standard WSGI server.

Flask using Nginx?

I am a .net developer coming over to python. I have recently started using Flask and have some quick questions about serving files.
I noticed a lot of tutorials focused on nginix and flask. However, I am able to run flask without nginx. I'm just curious as to why this is used together (nginx and flask). Is nginx only for static files?
Nginx is a proxy server, imagine your apps have multiples microservices on differents languagues.
For more info NGINX REVERSE PROXY
On a development machine flask can be run without a webserver (nginx, apache etc) or an application container (eg uwsgi, gunicorn etc).
Things are different when you want to handle the load on a production server. For starters python is relatively very slow when it comes to serving static content where as apache / nginx do that very well.
When the application becomes big enough to be broken into multiple separate services or has to be horizontally scaled, the proxy server capabilities of nginx come in very handy.
In the architectures I build, nginx serves as the entry point where ssl is terminates and the rest of the application is behind a VPN and firewall.
Does this help?
From http://flask.pocoo.org/docs/1.0/deploying/ :
"While lightweight and easy to use, Flask’s built-in server is not suitable for production as it doesn’t scale well. Some of the options available for properly running Flask in production are documented here."

difference between uwsgi module in nginx and uwsgi server

I'm new to linux development. I'm a bit confused on the documentation i read.
My ultimate goal is to host a simple python backed web service that would examine an incoming payload, and forward it to other server. This should be less than 30 lines of code in python.
I'm planning to use nginx to serve up python file. From my research, i also need a python web framework. I chose to go with uwsgi. I'm so confused. which one do I need? an nginx uwsgi module, or uwsgi server? i don't want to put django just for this simple purpose.
the nginx documentation mention that
Do not confuse the uwsgi protocol with the uWSGI server (that speaks the uwsgi protocol)
So, does that mean, i don't need to install uwsgi server separately? do i just install nginx, and start configuring? I'm using nginx 1.4.4
Could someone share a step by step configuration procedure on how to configure uwsgi with nginx, along with a sample python code(hello world maybe)? i can configure nginx just fine, but i don't know how to make it serve python pages. all the docs i could find involves having django on top.
You're mixing up things, so let me clarify.
Python's standard way of publishing applications via web servers is WSGI--you can think of it as a Python's native CGI. uWSGI is a WSGI-compliant server that uses uwsgi protocol to talk to other uWSGI instances or upstream servers. Usually the upstream server is nginx with HttpUwsgiModule that allows it to communicate using uwsgi protocol--with nginx you have additional layer of protection for your app server, load balancing and serving the static files. In most scenarios, You Should Be Using Nginx + UWSGI. To answer your question, uWSGI is installed and run separately from nginx, and they both need to be configured to communicate to each other.
Pure WSGI is pretty low-level, so you may want to use a WSGI-compliant framework. I guess the top two are Django and Flask.
For a hello world Flask setup, Serving Flask With Nginx seems to be a good article.

Running python through fastCGI for nginx

I am looking to run standalone python scripts through fcgi for use with nginx, but I have no idea where to start with spawning the processes. Currently, I have PHP successfully with nginx+fcgi, but I'm unsure if/how I can do the same with python. Any suggestions on where to start?
See the python docs section on FCGI. Basically, with Python, you use the WSGI interface on top of an fcgi server which talks to the web server (the fcgi client).
See Python + FastCGI for a couple of Python fcgi servers.
Edit:
This nginx wiki page explains exactly how to set up Python with nginx using fcgi.
This wiki page describes the uWSGI module for nginx, which is the natural way to use Python with a web server, if you don't really need to use fcgi. This blog entry also looks like good info on uWSGI.
In production, Apache + mod_wsgi or Nginx + mod_wsgi? has some useful info for nginx mod_wsgi as well.

Should I use Pylon's Paste to host my Pylons website? Or can I use Apache?

I'm looking into Pylons and was wondering, should I use Paste as the webserver or can I use Apache?
Are there advantages to using Paste?
Would you recommend against using Apache?
How should I host the sites?
I guess it depends on whether you need webserver for development or production. For development just stick to Paste. I don't think there's one best way to host production application, but if you're not a pro in system administration, you can just go with Apache and mod_wsgi.
By the way, there's a great and comprehensive comparison of Python WSGI servers at http://nichol.as/benchmark-of-python-web-servers.
I'm using Nginx (with fastcgi) or Apache for hosting Pylons sites, mostly because lack of some "production" features in Paste, but for development Paste is very usefull and handy.

Categories