'Develop/Web'에 해당되는 글 1건

  1. 2012.02.10 Apache + mod_wsgi + Django install from source

Apache + mod_wsgi + Django install from source

Develop/Web 2012. 2. 10. 20:43

OpenSSL (필요한 경우만)


http://www.openssl.org/
http://httpd.apache.org/docs/2.0/mod/mod_ssl.html
 

# ./config --prefix=/path/to/openssl
# make; make install 

# openssl genrsa -des3 -out server.key 1024
# openssl req -new -key server.key -out server.csr
# openssl x509 -req -days 90 -in server.csr -signkey server.key -out server.crt

 


Apache


http://httpd.apache.org/

[mpm-worker]
# ./configure --prefix=/path/to/apache --enable-so --with-mpm=worker

[mpm-worker, ssl]
# ./configure --prefix=/path/to/apache  --enable-so --with-mpm=worker \
> --enable-ssl --with-ssl=/path/to/openssl

(debug mode)
--enable-maintainer-mode

# make; make install 


extra/httpd-wcgi.conf 생성
http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/ 
http://gauryan.blogspot.com/2010/10/apache-django-modwsgi.html
http://bryanhelmig.com/setting-up-ubuntu-10-04-with-apache-memcached-ufw-mysql-and-django-1-2-on-linode/ 
https://code.djangoproject.com/wiki/django_apache_and_mod_wsgi 
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango 

LoadModule wsgi_module modules/mod_wsgi.so


NameVirtualHost *:80

<VirtualHost *:80>

    ServerName localhost

    DocumentRoot /app/foo


    <Location />
        Order allow,deny

        Allow from all

    </Directory>


    # setting 에서 static file을 /app/foo/static 으로 한 경우 
    Alias /static /app/foo/static
    <Location /static>
        Order allow,deny
        Allow from all
    </Location> 


    WSGIScriptAlias / /app/foo/django.wsgi

</VirtualHost>


httpd.conf 파일 수정

DocumentRoot /path/to/document/root
ServerName MyServerName:80 
<Directory "/path/to/document/root">
    ... 
 
</Directory>

Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-default.conf
Include conf/extra/httpd-wcgi.conf  


포트 막혀있는 경우 80번 열어주기

/etc/sysconfig/iptables 에 다음 추가

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# /etc/init.d/iptables restart
혹은
# service iptables restart 




Python


http://python.org/getit/ 

# ./configure --prefix=/path/to/python \
--enable-shared

# make; make install 




mod_wsgi


http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide
http://code.google.com/p/modwsgi/wiki/PerformanceEstimates

# ./configure --with-apxs=/path/to/httpd/bin/apxs \
> --with-python=/path/to/pythton/bin/python

 

# make; make install 



Django


https://www.djangoproject.com/download/

# python setup.py install




Sample Project


# cd /app/
# django-admin.py startproject foo
# cd /app/foo
# ls
__init__.py  __init__.pyc  manage.py  settings.py  urls.py  urls.pyc

# cat > django.wsgi
import os

import sys

sys.path.append('/app/')

os.environ['DJANGO_SETTINGS_MODULE'] = 'foo.settings'


import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()



: