首页 > 代码库 > linux下apache https 虚拟主机配置

linux下apache https 虚拟主机配置

如果单纯仅仅想在数据传输时加密传输,那么ssl证书是不须要认证的,可是浏览器打开时会有警告信息。如果我们做的不是一个公众产品那么也还好啦。

例如以下是今天学习时的一个笔记,事实上我用的是真实环境。

环境:CentOS 64。 32bit。Apache 2.2.15;

1.检查apache是否安装了mod_ssl.so模块。

检查方法是查看是否在modules(/etc/httpd/modules/)下存在。不存在那么安装(yum -y install mod_ssl)。

2.生成证书和密钥

1)生成密钥

命令:openssl genrsa 1024 > server.key

说明:用128位rsa算法生成密钥,得到server.key文件。

2) 生成证书请求文件

命令:openssl req -new -key server.key > server.csr

说明:用步骤1生成的密钥生成证书请求文件server.csr。这一步会有非常多问题,依照自己的须要输入就可以。

3): 生成证书

命令:openssl req -x509 -days 365 -key server.key -in server.csr > server.crt

说明:用步骤1,2的密钥和证书请求生成证书server.crt。-days參数指明证书有效期,单位为天。

3.改动apache配置文件(httpd.conf)

1)加入监听port

Listen 443

2)载入mod_ssl模块

LoadModule ssl_module modules/mod_ssl.so

3)配置虚拟主机

NameVirtualHost 121.127.246.429:443
<VirtualHost 121.127.246.429:443>
	DocumentRoot /data/www/1234567
	ServerName 1234567.mo.com
	SSLEngine On
	SSLOptions +StrictRequire
	SSLCertificateFile /data/conf/httpd/server.crt
	SSLCertificateKeyFile /data/conf/httpd/server.key
	DirectoryIndex index.html index.php
	<Directory "/data/www/1234567">
		#Options Indexes FollowSymLinks
		Options FollowSymLinks
		AllowOverride None
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>
4.訪问

https://1234567.mo.com


linux下apache https 虚拟主机配置