nginx Django的郊区不起作用

我试图设置django在某些郊区,让/myproject ,用nginx和uwsgi。 但是,我无法得到它的工作。 无论我尝试,似乎uwsgi_modifier1 30; 选项不起作用。 我总是得到加倍path,而不是localhost:8000/myproject ,我得到localhost:8000/myproject/myproject

我错过了什么? 这里是相关的文件:

Django的urls.py

 from django.conf.urls import patterns, include, url from django.http import HttpResponse # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # Examples: url(r'^$', lambda x: HttpResponse('Hello world'), name='home'), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), ) 

除了添加数据库信息之外,我没有更改任何默认的django settings.py。 这里是nginx的conf文件:

 upstream mydjango { server unix:///home/username/www/myproject/c.sock; } server { listen 8000; server_name localhost; location /myproject/ { uwsgi_pass mydjango; include /home/username/www/myproject/uwsgi_params; uwsgi_param SCRIPT_NAME /myproject; uwsgi_modifier1 30; } } 

现在我从命令行开始uwsgi:

 uwsgi --socket c.sock --module myproject.wsgi --chmod-socket=666 

在日志中我没有发现任何错误,只是404,因为8000端口上没有nginx conf / path,但没有匹配/myproject/myproject/ django url规则。 那么我的错误在哪里? 如果这是相关的,我试图在debian喘息,nginx最新从主线,python-3.3.2

你尝试使用rewrite而不是uwsgi_modifier1

 ... location /myproject { rewrite /myproject(.*) $1 break; include /home/username/www/myproject/uwsgi_params; uwsgi_pass mydjango; } ... 

我得到它的工作! 诀窍是告诉Django与FORCE_SCRIPT_PATHpath以及修改静态path。 对于我来说,这个解决scheme已经足够好了,因为只有Django的本地设置和nginx.conf中configuration了proxl。

Ubuntu 14.04 + Django 1.8 + uwsgi 1.9.17.1 + nginx 1.4.6

nginx.conf:

 server { listen 80; server_name 192.168.1.23 firstsite.com www.firstsite.com; location = /favicon.ico { access_log off; log_not_found off; } location /1/static { root /home/ubuntu/firstsite; } location /1 { include uwsgi_params; uwsgi_param SCRIPT_NAME /1; uwsgi_modifier1 30; uwsgi_pass unix:/home/ubuntu/firstsite/firstsite.sock; } } 

将三行添加到Django firstsite / settings.py:

 FORCE_SCRIPT_NAME = '/1' ADMIN_MEDIA_PREFIX = '%s/static/admin/' % FORCE_SCRIPT_NAME STATIC_URL = '%s/static/' % FORCE_SCRIPT_NAME 

为了完整性,这里是我在〜home / Env中使用virtualenv的uwsgi firstsite.ini:

 [uwsgi] project = firstsite base = /home/ubuntu chdir = %(base)/%(project) home = %(base)/Env/%(project) module = %(project).wsgi:application master = true processes = 5 socket = %(base)/%(project)/%(project).sock chmod-socket = 664 vacuum = true