centos apache https 安装 配置步骤

1,查看apache是否安装ssl模块

[root@localhost 桌面]# ll /etc/httpd/conf.d/
总用量 32
-rw-r--r--. 1 root root 2926 7月  18 23:30 autoindex.conf
-rw-r--r--. 1 root root 1185 7月  21 13:37 php.conf
-rw-r--r--. 1 root root  366 7月  18 23:30 README
-rw-r--r--. 1 root root 9434 11月 21 15:56 ssl.conf
-rw-r--r--. 1 root root 1252 7月  18 23:22 userdir.conf
-rw-r--r--. 1 root root  824 7月  18 23:22 welcome.conf

如果没有ssl.conf,则证明没有安装ssl模块

2,安装ssl模块

yum install mod_ssl

安装成功后,集即可看到ssl 配置文件:ssl.conf

3,生成证书和密钥(摘自:http://www.cnblogs.com/best-jobs/p/3298258.html)

linux下

步骤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

vim /etc/httpd/conf.d/ssl.conf

修改下面三行:

DocumentRoot "/var/www/html/网站项目目录"
#server.crt,server.key为第二部生成的密钥文件
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/server.key

4、  重新启动apache

用https方式访问,查看是否生效

5,配置https 支持.htaccess

开启后若配置的伪静态的页面无法访问,可能是因为ssl.conf配置的虚拟主机不支持.htaccess,添加支持即可,与http.conf中配置虚拟主机一样,即在DocumentRoot下添加Directory相关配置项即可

<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/网站项目目录" 
#ServerName www.example.com:443
<Directory "/var/www/网站项目目录/"> 
Options FollowSymLinks
AllowOverride All
Allow from all
Require all granted
</Directory>

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

....
...
</VirtualHost>

猜你喜欢

转载自blog.csdn.net/xfcy1990/article/details/89215747
今日推荐