Search code examples
pythonlinuxcentoswsgigunicorn

Serving a request from gunicorn


Trying to setup a server on Rackspace.com.

Have done the following things:

  • Installed Centos 6.3
  • Installed Python 2.7
  • Installed gunicorn using the "Quick Start" on their home page: gunicorn.org/

In the quick start, a "hello world" application seems to be initialized:

Create file "myapp.py":

(tutorial) $ vi myapp.py
(tutorial) $ cat myapp.py

Contents of "myapp.py"

def app(environ, start_response):
   data = "Hello, World!\n"
   start_response("200 OK", [
       ("Content-Type", "text/plain"),
       ("Content-Length", str(len(data)))
   ])
   return iter([data])

Since I know very little about servers, I do not know what to do next. I tried typing the server's IP address into the browser, but that seemed to result in a timeout.

I'm not sure if there is:

  • something else that needs to be installed. Nginx is mentioned under "deploy" on the gunicorn website. Looks like Nginx is a proxy server which is confusing to me because I thought gunicorn was a server. Not sure why I need two servers?
  • something that needs to be configured in gunicorn
  • something that needs to be configured on the server itself
  • something that else entirely that needs to be done in order to actually serve a request

What are the next steps?

Thanks so much!


Solution

  • looking at the quickstart guide, you probably should have run

    (tutorial) $ ../bin/gunicorn -w 4 myapp:app
    

    which should have produced a line that looks a bit like:

    Listening at: http://127.0.0.1:8000
    

    Among others. see if you can access your site at that address.

    Also Note that 127.0.0.1 is the loopback address; accessible only from that host itself. To get gunicorn to bind to a different option, pass it --bind 0.0.0.0:80, as Jan-Philip suggests.

    Since you mention rackspace, its possible that you may need to adjust the firewall settings to allow incoming connections to the desired ports.