ubuntu10.10+django+apache2+(mod-python 或 wsgi)

陈着 posted @ Mar 12, 2011 04:22:44 PM in server , 4606 阅读

这几天一直在折腾django在apache上的部署,网上的资料鱼龙混杂,特将经验记录下来,希望能帮助更多的人。

mod-python:

1.安装apache,mod-python:

sudo apt-get install apache2 libapache2-mod-python

2.在/etc/apache2/available/目录下建立配置文件:mytest

<VirtualHost *:80>
	ServerName localhost
	DocumentRoot /home/sarlmolapple/workspace/django-site/mytest
	<Directory "/home/sarlmolapple/workspace/django-site">
		Allow from all
		SetHandler python-program
    		PythonHandler django.core.handlers.modpython
    		SetEnv DJANGO_SETTINGS_MODULE mytest.settings
    		PythonDebug On
    		PythonPath "['/home/sarlmolapple/workspace/django-site', '/home/sarlmolapple/workspace/django-site/mytest', '/home/sarlmolapple/workspace/django-site/mytest/mysite'] + sys.path"
	</Directory>
</VirtualHost>

注:django项目为mytest, 路径为:/home/sarlmolapple/workspace/django-site/mytest,

‘/home/sarlmolapple/workspace/django-site/mytest/mysite’为mytest中的app所在路径

3.运行命令:

sudo a2ensite mytest
sudo /etc/init.d/apache2 reload

然后你在浏览器中输入http://localhost就可以看到你想要看到的页面了

WSGI:

1.安装apache,mod-python:

sudo apt-get install apache2 libapache2-wsgi-python

2.在/etc/apache2/available/目录下建立配置文件:mytest

<VirtualHost *:80>
    ServerName wsgi.mytest
    DocumentRoot /home/sarlmolapple/workspace/django-site/mytest
    <Directory /home/sarlmolapple/workspace/django-site/mytest>
        Order allow,deny
        Allow from all
	PythonPath "['/home/sarlmolapple/workspace/django-site', '/home/sarlmolapple/workspace/django-site/mytest', '/home/sarlmolapple/workspace/django-site/mytest/mysite'] + sys.path"
    </Directory>
    WSGIDaemonProcess wsgi.mytest processes=2 threads=15 display-name=%{GROUP}
    WSGIProcessGroup wsgi.mytest
    WSGIScriptAlias / /home/sarlmolapple/workspace/django-site/mytest/apache/django.wsgi
</VirtualHost>

3.在mytest目录下建立apache/django.wsgi

import os
import sys

sys.path.append('/home/sarlmolapple/workspace/django-site')
sys.path.append('/home/sarlmolapple/workspace/django-site/mytest')
sys.path.append('/home/sarlmolapple/workspace/django-site/mytest/mysite')

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

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

注: mytest路径为:/home/sarlmolapple/workspace/django-site/mytest,‘/home/sarlmolapple/workspace/django-site/mytest/mysite’为mytest中的app所在路径

4.运行命令:

sudo a2ensite mytest
sudo /etc/init.d/apache2 reload

同理,你在浏览器中输入http://localhost就可以看到你想要看到的页面了。

Avatar_small
Alexander Deamer 说:
Feb 18, 2019 04:07:52 PM

The formally found items have been herd for the individuals. The race of the bloggers and essay on time review is marked for the people. The truth is elevated for the major chunk of the facility and its image for the people.

Avatar_small
cleaning services 说:
Sep 17, 2019 09:56:54 PM

The neighborhood house cleansing services businesses charge in a different way; it mostly depends upon your needs. So, if you're doing “deep cleansing, ” they offer a group sum amount for the entire job, and if you're living inside a studio, they might charge a person from two hundred to three hundred AED that could go as much as 1, 500 AED for any 5-bedroom condo.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter