请求的URL未找到(Django Nginx Gunicorn)

时间:2015-06-21 06:05:31

标签: python django nginx gunicorn

尝试访问除根网址之外的任何网址时出现以下错误:

Not Found

The requested URL /groups/test/ was not found on this server.

我认为问题可能出现在下列之一:

urls.py:

from django.conf.urls import include, url
from django.contrib import admin

from groups import views

urlpatterns = [
    # Examples:
    url(r'^$', views.home_page, name='home'),
    url(r'^groups/(.+)/$', views.view_group, name='view_group')
]

nginx.conf模板:

server {
    listen 80;
    server_name SITENAME;

    location /static {
        alias /home/ghust1995/sites/SITENAME/static;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://unix:/tmp/SITENAME.socket;
    }
}

如何解决这个问题?

编辑:

gunicorn-upstart模板:

description "Gunicorn server for SITENAME"

start on net-device-up
stop on shutdown

respawn

setuid ghust1995
chdir /home/ghust1995/sites/SITENAME/source

exec ../virtualenv/bin/gunicorn --bind unix:/tmp/SITENAME.socket itagroups.wsgi:application

1 个答案:

答案 0 :(得分:0)

您的location /应该重定向到Gunicorn运行的端口。

location / {
            proxy_pass http://127.0.0.1:<Gunicorn Port>;
            proxy_set_header X-Forwarded-Host $server_name;
            proxy_set_header X-Real-IP $remote_addr;
            add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }