總所周知,我們在訪問自己的Apache時默認的是80埠,那么如何重定向到443埠呢?至于為何要重定向到443埠,請看這篇文章:
關于Apache服務器配置SSL證書的那些事(保姆級教程)https://blog.csdn.net/m0_65831893/article/details/122161932
https://blog.csdn.net/m0_65831893/article/details/122161932 在配置好SSL證書后,我們訪問https://...是沒有問題的,但是如果我們單單輸入網址進行訪問時,默認訪問的還是http://...
這個時候重定向就起到作用了,首先打開我們的httpd.conf檔案,找到下面這句話
LoadModule rewrite_module modules/mod_rewrite.so
如果前面有#號,把#號去掉,確保我們的Apache重寫模塊有打開
緊接著打開我們的httpd-vhosts.conf檔案
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "${INSTALL_DIR}/htocs"
#在我們配置好的虛擬域名檔案中加入這三句話,Apache服務器便會在訪問80埠時重定向到443埠
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
<Directory "${INSTALL_DIR}/htocs">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
完成以上步驟后,重啟Apache服務,訪問80埠時,Apache便會重定向到443端
(以上內容僅供學習參考,若有錯誤之處歡迎指正交流)
各位看官老爺,收藏起來唄,萬一以后用得到呢,再不行點個贊再走/(ㄒoㄒ)/~~
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/396153.html
標籤:其他
