Apache httpd 配置HTTPS SSL访问 443
3. 配置Apache Web服務器
首先,修改下面的配置文件。僅需配置紅色部分?SSLCertificateFile?和?SSLCertificateKeyFile
# vim /etc/httpd/conf.d/ssl.conf
#
# When we also provide SSL we have to listen to the?
# the HTTPS port in addition.
#
Listen 443 https
##
## SSL Virtual Host Context
##
<VirtualHost _default_:443>
# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html/a.com"
ServerName www.a.com:443
### overwrite the following parameters ###
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/server.key
### The following parameter does not need to be modified in case of a self-signed certificate. ###
### If you are using a real certificate, you may receive a certificate bundle. The bundle is added using the following parameters ###
SSLCertificateChainFile /etc/pki/tls/certs/example.com.ca-bundle
然后,重新啟動httpd服務使更改生效
# systemctl restart httpd ? ? ? ? ?// 或者 ?/etc/init.d/httpd restart
Web服務器現在可以使用HTTPS
?
4. 調整虛擬主機
Apache Web服務器可以配置為多個Web站點。這些站點在httpd的配置文件中以虛擬主機的形式定義。例如,讓我們假設我們的Apache Web服務器托管站點為www.a.com,網站所有的文件都保存在/var/www/html/a.com/目錄。
對于虛擬主機,典型的HTTP配置是這樣的。
# vim?
?
#??vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost *:80>
?ServerName www.a.com
?Redirect permanent / https://www.a.com/
?DocumentRoot "/var/www/html/a.com"
?<Directory "/var/www/html/a.com">
?Options None
?AllowOverride None
?Require all granted
?</Directory>
</VirtualHost>
?
?
# vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:443
<VirtualHost *:443>
? ? SSLEngine on
? ? SSLCertificateFile /etc/pki/tls/certs/server.crt
? ? SSLCertificateKeyFile /etc/pki/tls/private/server.key
? ? <Directory /var/www/html/virtual-web>
? ? ? ? AllowOverride All
? ? </Directory>
? ? ServerAdmin email@example.com
DocumentRoot /var/www/html/a.com
ServerName www.a.com
</VirtualHost>
?
需要按照上面的配置,定義每個虛擬主機。添加虛擬主機后,重新啟動Web服務。
# systemctl restart httpd
現在的虛擬主機就可以使用HTTPS
?
5. 強制Apache Web服務器始終使用https
如果由于某種原因,你需要站點的Web服務器都只使用HTTPS,此時就需要將所有HTTP請求(端口80)重定向到HTTPS(端口443)。 Apache Web服務器可以容易地做到這一點。
1,強制主站所有Web使用(全局站點)
如果要強制主站使用HTTPS,我們可以這樣修改httpd配置文件:
# vim /etc/httpd/conf/httpd.conf
ServerName www.example.com:80
Redirect permanent / https://www.example.com
重啟Apache服務器,使配置生效:
# systemctl restart httpd
?
2,強制虛擬主機(單個站點)
如果要強制單個站點在虛擬主機上使用HTTPS,對于HTTP可以按照下面進行配置:
#?vim /etc/httpd/conf.d/httpd-vhosts.conf
<VirtualHost *:80>
? ? ServerName www.a.com
? ??Redirect permanent / https://www.a.com/
</VirtualHost>
重啟Apache服務器,使配置生效:
# systemctl restart httpd
單個站點全部使用HTTPS,則?http://www.a.com?會強制重定向跳轉到?https://www.a.com
總結
以上是生活随笔為你收集整理的Apache httpd 配置HTTPS SSL访问 443的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python Chrome + sele
- 下一篇: pyTorch实现C3D模型的视频行为识