I'm trying to deploy a readthedocs instance on my own server. The recommended way to deploy is using Gunicorn + nginx with postgres. Because there's basically no documentation on how to do this (except from their fabfiles which of course, only works on their server), I've been trying to setup my own server, manually.

Here's my nginx.conf:

server {
    listen 80 default;
    server_name mysite.com;
    access_log /var/log/nginx/mysite.access.log;
    error_log /var/log/nginx/mysite.error.log;

    location /favicon.ico {
        root /home/mysite/Code/checkout/readthedocs.org/media/images;

    location robots.txt {
        root /home/mysite/Code/checkout/readthedocs.org/media;

    location /static/ {
        alias /home/mysite/Code/checkout/readthedocs.org/media/;
        expires 30d;

    location /media/ {
        alias /home/mysite/Code/checkout/readthedocs.org/media/;
        expires 30d;

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;

The settings.py for django configuration can be found here. The only thing I changed on settings.py is I add gunicorn on INSTALLED_APPS so I can run gunicorn with it.

The command I use to run the gunicorn server is:

./manage.py run_gunicorn -b

Then if I try to access from a local browser, it would work, but always show a 404 page, no matter what URL I entered. Running ./manage.py runserver will run everything correctly.

Now I am not a sysadmin, and have basically 0 experience with django, gunicorn, or nginx before. I've been googling and playing around the configuration for weeks, with 0 result. My question is:

  1. How do I know which django's route called by gunicorn? Can I debug this? All log files that I can find didn't show this.
  2. Do you see anything wrong with my configuration file? If so, could you please tell me what's wrong?

Thank you very much.


Have you tried loading the site at port 8888 to ensure that it's running correctly?

Does the 404 message you're getting have nginx in the text? This would indicate that nginx is having the problem finding the resource and not the service on port 8888. In which case you can troubleshoot your config file.

You're logging the access in nginx, so you can look at your log for some more information. tail -n 10 /var/log/nginx/mysite.access.log will let you see the last 10 lines of that log.

By default, nginx uses the combined log format:

log_format combined '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';

That should help you figure out what each column in your log file means.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.