使用runfcgi时,Django URL会重复出现

时间:2014-02-21 17:18:27

标签: django nginx flup

我有以下urlpatterns:

urlpatterns = patterns('',
   url(r'^$',         'opeiaa.views.home',    name='home'),
   url(r'^store/$',   'opeiaa.views.store',   name='store'),
   url(r'^resume/$',  'opeiaa.views.resume',  name='resume'),
   url(r'^contact/$', 'opeiaa.views.contact', name='contact'),
   url(r'^gallery/',  include('gallery.urls')),

   url(r'^admin/',    include(admin.site.urls)),
)

...我正在使用这种模板标签:

<a class='nav-link' href='{% url 'contact' %}'>Contact</a>

网址在http://localhost:8000/contact/页面中呈现。使用./manage.py runserver进行测试时,一切正常......

...但我运行./manage.py runfcgi - 然后当我导航到联系页面时,导航中的网址指向http://localhost:8000/contact/contact/!我已经尝试在开头设置斜杠以使URL绝对,但如果没有它,URL似乎是绝对的。

我使用nginx作为前端,相关的配置是:

location / {
    include fastcgi_params;
    fastcgi_pass unix:/tmp/django.sock;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_pass_header Authorization;
    fastcgi_intercept_errors off;
}

我正在使用Django 1.6&amp; Python 2.7.4。有人有任何见解吗?

1 个答案:

答案 0 :(得分:0)

8个月之后,当我在另一个网站上发生这种情况时,我发现了这一点,因为在SCRIPT_NAME之前设置了include fastcgi_params

最终的工作配置代码段:

location / {
    include fastcgi_params;
    fastcgi_param SCRIPT_NAME "";
    fastcgi_pass unix:/tmp/django.sock;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_pass_header Authorization;
    fastcgi_intercept_errors off;
}