views:

87

answers:

1

Hello

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'^$',
            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',),            
)

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]
+1  A: 

This seems to be your problem:

RewriteCond %{HTTP_HOST} ^jalka\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) cgi-bin/fifa2010.fcgi/$1 [QSA,L]

Lets take an example of a request to http://jalka.domain.com/jalka.html If jalka.html does not exist, your code redirects you to http://jalka.domain.com/cgi-bin/fifa2010.fcgi/jalka.html. When Apache looks for /cgi-bin/fifa2010.fcgi/jalka.html it won't find it, because fifa2010.fcgi is a file, not a directory. As a result, you get redirected to http://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.

Jack M.
Thanks! you came up with almost exact description of what i found myself - i solved it btw. I dont know why exactly, but those two rewrites for .fcgi files seemed to be working differently because one of them was for subdomain, which's domain was essentially domain alias for domain.com. When i tried to set it up exactly like that for subdomain of domain.com it worked differently by adding subdomain(jalka) as part of request path. In process of figuring this out i was getting paths like domain.com/cgi-bin/fifa2010.fcgi/jalka/-those generated django errors, but at least i knew i was getting clos
Zayatzz