目录

  • Apache部署


Apache部署

简介: apache是世界使用排名第一的web服务器软件,它可以运行在几乎所有广泛使用的计算机平台上,是最流行的web服务器端软件之一。

特点: 擅长处理动态请求;高并发处理能力弱。

这里使用ubuntu进行配置,其优点如下:

(1)开机apache2等自动启动,不需要额外配置

(2)安装软件非常方便,apt-get搞定

(3)安装ssh,git等也非常容易

安装步骤:

apache http服务器的mod_wsgi扩展模块,实现了python WSGI标准,可以支持任何兼容python WSGI标准的python应用。

1.安装apache2建立连接。

apache 与 Python WSGI 对比_配置文件


建立python3和apache2的连接

apache 与 Python WSGI 对比_apache_02


2.确认安装的apache2版本号

apache 与 Python WSGI 对比_django_03


3.在虚拟机中安装pip3和django

apache 与 Python WSGI 对比_django_04


若提示pip版本太低,更新pip

apache 与 Python WSGI 对比_Apache_05


apache 与 Python WSGI 对比_django_06


4.准备一个新网站

新建一个网站配置文件,ubuntu的apache2配置文件在 /etc/apache2/下,使用 vi /etc/apache2/sites-available /blog . conf 指令。

其中site-enabled是apache2正在使用的网站配置文件,site-available是apache2可用的网站配置文件。

apache 与 Python WSGI 对比_django_07

<VirtualHost *:80> 
ServerName localhost:80				#填写自己的域名或ip
ServerAlias otherdomain.com,xxx,  #指向同一个网站的其他域名
ServerAdmin xxx@Email.com			#邮箱

Alias /media/ /home/user/项目名称/media/		#上传文件
Alias /static/ /home/user/项目名称/static/ 	#静态文件(js、css、图片、视频等)

<Directory /home/user/项目名称/media>		#文件授权
	 Require all granted 
</Directory> 
<Directory /home/user/项目名称/static> 
    Options FollowSymLinks # 禁止目录索引
	Require all granted 
</Directory>

WSGIScriptAlias / /home/user/项目名称/项目名称/wsgi.py

<Directory /home/user/项目名称/项目名称>
	<Files wsgi.py> 
		Require all granted 
	</Files> 
</Directory> 
</VirtualHost>

apache 与 Python WSGI 对比_apache_08


apache 与 Python WSGI 对比_python_09

5.修改wsgi.py文件

如果没有创建django项目的话先进行创建。

上面配置中写到的 WSGIScriptAlias / /home /liu/Desktop /blog/blog /wsgi.py 就是将apache2和我的网站blog联系起来了。

apache 与 Python WSGI 对比_配置文件_10


apache 与 Python WSGI 对比_apache_11


apache 与 Python WSGI 对比_Apache_12


测试一下:

apache 与 Python WSGI 对比_apache_13


再修改wsgi.py文件

apache 与 Python WSGI 对比_配置文件_14


6.修改目录权限

apache 与 Python WSGI 对比_apache_15


7.修改数据库权限

apache 与 Python WSGI 对比_django_16


8.启动网站

apache 与 Python WSGI 对比_apache_17


注意:

在Unbuntu中重启Apache服务器出现错误:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1.等等。解决方法:

使用 sudo vi /etc/apache2/apache2.conf 指令,给文件中加上一句 ServerName 127.0.1.1。