Background Image
Table of Contents Table of Contents
Previous Page  178 / 478 Next Page
Information
Show Menu
Previous Page 178 / 478 Next Page
Page Background

}

}

Reload Nginx and restart Gunicorn…

elspeth@server

:$

sudo service nginx reload

elspeth@server

:$

../virtualenv/bin/gunicorn superlists

.wsgi:application

And if we take another look at the site, things are looking much healthier. We can rerun

our FTs:

$

python3 manage.py test functional_tests --liveserver=superlists-staging.ottg.eu

Creating test database for alias 'default'...

..

---------------------------------------------------------------------

Ran 2 tests in 10.718s

OK

Destroying test database for alias 'default'...

Switching to Using Unix Sockets

When we want to serve both staging and live, we can’t have both servers trying to use

port 8000. We could decide to allocate different ports, but that’s a bit arbitrary, and it

would be dangerously easy to get it wrong and start the staging server on the live port,

or vice versa.

A better solution is to use Unix domain sockets—they’re like files on disk, but can be

used by Nginx and Gunicorn to talk to each other. We’ll put our sockets in

/tmp

. Let’s

change the proxy settings in Nginx:

server: /etc/nginx/sites-available/superlists-staging.ottg.eu.

[...]

location

/

{

proxy_set_header

Host

$host

;

proxy_pass

http://unix

:/tmp/superlists-staging.ottg.eu.socket

;

}

}

proxy_set_header

is used to make sure Gunicorn and Django know what domain it’s

running on. We need that for the

ALLOWED_HOSTS

security feature, which we’re about to

switch on.

Now we restart Gunicorn, but this time telling it to listen on a socket instead of on the

default port:

elspeth@server

:$

sudo service nginx reload

elspeth@server

:$

../virtualenv/bin/gunicorn --bind \

unix:/tmp/superlists-staging.ottg.eu.socket superlists

.wsgi:application

And again, we rerun the functional test again, to make sure things still pass:

150

|

Chapter 8: Testing Deployment Using a Staging Site