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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章