debianã§apache2+fastcgiãªç°å¢ã§djangoãåããã¡ã¢ãã®2
ç®çã¯dreamhostã«è¿ãç°å¢ããã¼ã«ã«ã®coLinux+debian etchãªç°å¢ã«æ§ç¯ãããã¨ã
ååã®apacheè¨å®ã«ãmod-fcgiåã³ãmod-rewriteã®è¨å®ãå ãã¦ãdjangoããã¸ã§ã¯ããã¤ãããããããã¼ã¸ã表示ããããã¨ã確èªããã
mod-fastcgiã¤ã³ã¹ãã¼ã«
æ£ããã¯
% sudo apt-get install libapache2-mod-fastcgi
æåééãã¦
% sudo apt-get install libapache2-mod-fcgid
ãã¦ã¦ãè¥å¹²ã¯ã¾ã£ãã®ã§æ³¨æâ¦ã£ã¦ãããªã®ä¿ºã ããâ¦orz
fastcgiåã³ãrewriteã®æå¹å
% sudo a2enmod fastcgi % sudo a2enmod rewrite
ããç¡å¹åããããã°a2dismod ... ã使ãã
apacheè¨å®ãã¡ã¤ã«ç·¨é
% cd /etc/apache2/sites-available % sudo vi django
ãã¦ä»¥ä¸ã®ããã«ç·¨é(socketã使ãå ´å)
FastCgiExternalServer /var/www/django/public/django.fcgi -socket /tmp/django.sock <VirtualHost *> ServerName django ErrorLog /var/log/apache2/django-error.log CustomLog /var/log/apache2/django-access.log combined DocumentRoot /var/www/django/public RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /django.fcgi/$1 [QSA,L] </VirtualHost>
django.fcgiãä½æã
ä¸èº«ã¯ç©ºã§ãã¾ããªãããå®è¡æ¨©éãå¿ è¦ãªç¹ã«æ³¨æã
% touch /var/www/django/public/django.fcgi % chmod 755 /var/www/django/public/django.fcgi % ls -la /var/www/django/public/django.fcgi -rwxr-xr-x 1 maedana maedana 0 2007-09-02 07:57 /var/www/django/public/django.fcgi
apacheåèµ·å
% sudo /etc/init.d/apache2 restart
djangoããã¸ã§ã¯ãä½æ
% django-admin.py startproject django Error: 'django' conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name.
æãããâ¦orz ã¨ããããã§
% django-admin.py startproject djangosite % cd djangosite
/tmp/django.sockãèµ·åã
以ä¸ã®ã³ãã³ãã§ä½æããã.sockãªãã¡ã¤ã«ã«apacheãå®è¡ãã¦ããã¦ã¼ã¶ã®rwx権éãå¿ è¦ã£ã½ãããããããããæ¨æ¥å°ä¸æéã¯ã¾ãã¾ãã£ãâ¦ã権éããªãç¶æ ã§èµ·åããã¨ãå ·ä½çã«ã¯ä»¥ä¸ã®ããã«ãã¦ãã°ã¤ã³ã¦ã¼ã¶æ¨©éã§èµ·åããã¨
% ./manage.py runfcgi daemonize=false socket=/tmp/django.sock
apacheã®ã¨ã©ã¼ãã°ã«ä»¥ä¸ã®ããã«ã§ãã
[Sun Sep 02 08:31:56 2007] [error] [client 10.0.2.2] (13)Permission denied: FastCGI: failed to connect to server "/var/www/django/public/django.fcgi": connect() failed [Sun Sep 02 08:31:56 2007] [error] [client 10.0.2.2] FastCGI: incomplete headers (0 bytes) received from server "/var/www/django/public/django.fcgi"
æ¨æ¥ã¯ãã¼ã£ã¨/var/www/django/public/django.fcgiã®æ¨©éã®åé¡ã ã¨æã£ã¦ããã ãã©ã/tmp/django.sockã®æ¨©éãåé¡ã ã£ããã¨ã«æ°ãã¤ããã®ã¯ä½æ ã夢ã®ä¸ã夢ã®ä¸ã®ä¿ºGJ!!ã¨ããããã§ãdebianã®å ´åããã©ã«ãã§www-dataã¦ã¼ã¶ãªã®ã§ä»¥ä¸ã®ããã«ããããããã¨ãã£ãã/tmp/django.sockãæ¶ããªãã¨ã¨ã©ã¼ãåºããçç±ã¯ããããªãã
% sudo rm /tmp/django.sock % sudo -u www-data ./manage.py runfcgi daemonize=false socket=/tmp/django.sock
åä½ç¢ºèª
http://django:10080/
ã«ã¢ã¯ã»ã¹ãã¦ããããã¼ã¸ãç¡äºåºãããã«ãªã£ãã