您的位置:首页 > 运维架构 > Apache

手把手教你:Ubuntu14+apache2+django1.7+python2.7下网页/网站部署

2015-03-11 14:41 253 查看
本人亲自尝试了网上众多的部署网页/网站方法,绝大多数都未能试验成功,这次的项目光部署这块遇到了很多问题,大概耗费了我一个星期。

本着:王道论坛中的赠人玫瑰,手留余香的精神。我把自己一路所走的历程发布出来。网上的部署过程十分复杂,我这里把能简化的部分全部简化,努力达到让各位快速部署的目的。

步骤1:

环境:

需要安装:django,mod_wsgi

执行命令:

sudo apt-get install python-setuptools

sudo apt-get install python-pip

sudo apt-get install apache2

easy_install django

sudo apt-get install libapache2-mod-wsgi

步骤2:

将你的网站/网页项目拷贝至Ubuntu目录下,比如我的django项目名叫search,拷贝后的目录为/home/chaoma/education/search

执行命令:ifconfig

在eth0中中岛inet addr后面的就是你的ip地址。比如我的ip地址是:inet addr:192.168.32.128

执行命令:vim /etc/hosts

在末尾添加如下内容

127.0.0.1 search.com

192.168.32.128 search.com

步骤3:

执行命令:

vim /etc/apache2/apache2.conf

在末尾添加这几行

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

#Server Name

ServerName 127.0.0.1

#this is the domain which you want to visit

ServerName search.com

步骤4:

执行命令:vim /etc/apache2/sites-available/search.conf

添加如下内容:

<VirtualHost *:80>

ServerName www.appoperation.com

ServerAlias appoperation.com

ServerAdmin qingyuanluofeng@163.com



<Directory /home/chaoma/education/search>

Require all granted

</Directory>



WSGIScriptAlias / /home/chaoma/education/search/search/wsgi.py



<Directory /home/chaoma/education/search/search>

<Files wsgi.py>

Require all granted

</Files>

</Directory>

</VirtualHost>

保存

步骤5:

执行命令:a2ensite search.conf

执行命令:service apache2 reload

执行命令:vim /home/chaoma/education/search/search/wsgi.py

将该文件中内容删除,然后用下面内容替代:

import os

PROJECT_DIR = os.path.dirname(os.path.dirname(__file__))#3

import sys # 4

sys.path.insert(0,PROJECT_DIR) # 5

os.environ["DJANGO_SETTINGS_MODULE"] = "search.settings" # 7

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

注意:如果你们的项目名不是叫search,那可以将以上的search统一用你们自己的项目名替换

至此,全文结束。

验证:

在ubuntu的浏览器中输入(注意不是你的主机的浏览器):你自己网站或网页的地址,可以访问了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: