Django 内部重定向
我有一个项目在我自己的开发计算机上(使用 mod_wsgi 为该项目提供服务)没有造成任何问题。在实时服务器(使用 mod_fastcgi)中,它会生成 500 个。
我的 url conf 是这样的:
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('jalka.game.urls')),
)
并且
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
from django.contrib.auth import views as auth_views
urlpatterns = patterns('jalka.game.views',
url(r'^$',
view = 'front',
name = 'front',),
url(r'^ennusta/(?P<game_id>\d+)/$',
view = 'ennusta',
name = 'ennusta',),
url(r'^login/$',
auth_views.login,
{'template_name': 'game/login.html'},
name='auth_login'),
url(r'^logout/$',
auth_views.logout,
{'template_name': 'game/logout.html'},
name='auth_logout'),
url(r'^arvuta/$',
view = 'arvuta',
name = 'arvuta',),
)
.htaccess 是这样的:
Options +FollowSymLinks
RewriteEngine on
RewriteOptions MaxRedirects=10
# RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]
AddHandler fastcgi-script .fcgi
RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]
注意,我还使用相同的 .htaccess 设置了其他项目,并且该项目运行得很好,具有更复杂的 url 和视图
fifa2010.fcgi:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys, os
DOMAIN = "domain.com"
APPNAME = "jalka"
PREFIX = "/www/apache/domains/www.%s" % (DOMAIN,)
# Add a custom Python path.
sys.path.insert(0, os.path.join(PREFIX, "htdocs/django/Django-1.2.1"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs/jalka"))
# Switch to the directory of your project. (Optional.)
os.chdir(os.path.join(PREFIX, "htdocs", APPNAME))
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % (APPNAME,)
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
艾伦
编辑:I增加最大重定向并出现不同类型的错误:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)文件名太长:访问 /www/apache/domains/www.domain .com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com /htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs /cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi -bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin /fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010 .fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi /jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka / 失败
,看起来它不断重定向回自身,但至于为什么 - 我不知道。
编辑2-解决了! 最后,当我将 .htaccess 更改为此时,它开始工作:
RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /cgi-bin/fifa2010.fcgi [QSA,L]
RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]
I have one project that in my own development computer (uses mod_wsgi to serve the project) caused no problems. In live server (uses mod_fastcgi) it generates 500 though.
my url conf is like this:
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('jalka.game.urls')),
)
and
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
from django.contrib.auth import views as auth_views
urlpatterns = patterns('jalka.game.views',
url(r'^
and .htaccess is like that:
Options +FollowSymLinks
RewriteEngine on
RewriteOptions MaxRedirects=10
# RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]
AddHandler fastcgi-script .fcgi
RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]
Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views
fifa2010.fcgi:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys, os
DOMAIN = "domain.com"
APPNAME = "jalka"
PREFIX = "/www/apache/domains/www.%s" % (DOMAIN,)
# Add a custom Python path.
sys.path.insert(0, os.path.join(PREFIX, "htdocs/django/Django-1.2.1"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs"))
sys.path.insert(0, os.path.join(PREFIX, "htdocs/jalka"))
# Switch to the directory of your project. (Optional.)
os.chdir(os.path.join(PREFIX, "htdocs", APPNAME))
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % (APPNAME,)
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
Alan
EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed
it looks like it keeps redirecting back to itself, but as to why - i have no idea.
Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:
RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /cgi-bin/fifa2010.fcgi [QSA,L]
RewriteCond %{HTTP_HOST} ^subdomain\.otherdomain\.eu$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/django.fcgi/$1 [QSA,L]
,
view = 'front',
name = 'front',),
url(r'^ennusta/(?P<game_id>\d+)/
and .htaccess is like that:
Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views
fifa2010.fcgi:
Alan
EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed
it looks like it keeps redirecting back to itself, but as to why - i have no idea.
Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:
,
view = 'ennusta',
name = 'ennusta',),
url(r'^login/
and .htaccess is like that:
Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views
fifa2010.fcgi:
Alan
EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed
it looks like it keeps redirecting back to itself, but as to why - i have no idea.
Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:
,
auth_views.login,
{'template_name': 'game/login.html'},
name='auth_login'),
url(r'^logout/
and .htaccess is like that:
Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views
fifa2010.fcgi:
Alan
EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed
it looks like it keeps redirecting back to itself, but as to why - i have no idea.
Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:
,
auth_views.logout,
{'template_name': 'game/logout.html'},
name='auth_logout'),
url(r'^arvuta/
and .htaccess is like that:
Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views
fifa2010.fcgi:
Alan
EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed
it looks like it keeps redirecting back to itself, but as to why - i have no idea.
Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:
,
view = 'arvuta',
name = 'arvuta',),
)
and .htaccess is like that:
Notice, that i have also other project set up with same .htaccess and that one is running just fine with more complex urls and views
fifa2010.fcgi:
Alan
EDIT:I increased maximum redirects and got different kind of error:[Wed Jun 9 15:11:46 2010] [error] [client 84.50.104.242] (63)File name too long: access to /www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/www/apache/domains/www.domain.com/htdocs/cgi-bin/fifa2010.fcgi/jalka/ failed
it looks like it keeps redirecting back to itself, but as to why - i have no idea.
Edit2- Solved!
In the end, when i changed my .htaccess to this it started working:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是您的问题:
让我们以请求
http://jalka.domain.com/jalka.html
为例。如果 jalka.html 不存在,您的代码会将您重定向到http://jalka.domain.com/cgi-bin/fifa2010.fcgi/jalka.html
。当 Apache 查找/cgi-bin/fifa2010.fcgi/jalka.html
时,它不会找到它,因为fifa2010.fcgi
是一个文件,而不是一个目录。因此,您会被重定向到http://jalka.domain.com/cgi-bin/fifa2010.fcgi/cgi-bin/fifa2010.fcgi/jalka.html
。再次,找不到该文件。这就是您最终出现文件名太长错误的原因,因为此重定向会一遍又一遍地发生。
This seems to be your problem:
Lets take an example of a request to
http://jalka.domain.com/jalka.html
If jalka.html does not exist, your code redirects you tohttp://jalka.domain.com/cgi-bin/fifa2010.fcgi/jalka.html
. When Apache looks for/cgi-bin/fifa2010.fcgi/jalka.html
it won't find it, becausefifa2010.fcgi
is a file, not a directory. As a result, you get redirected tohttp://jalka.domain.com/cgi-bin/fifa2010.fcgi/cgi-bin/fifa2010.fcgi/jalka.html
. Yet again, this file cannot be found.This is how you end up with a filename too long error, because this redirect happens over and over again.