Apache 设置 80 端口自动跳转 443 端口 - NOTEBOOK
Apache 设置 80 端口自动跳转 443 端口
其他Posted on 2022-12-24
摘要 : 自动将http 80变成https 443
先启用 RewriteEngine on
sudo a2enmod rewrite
编辑配置文件
sudo nano /etc/apache2/sites-available/000-default.conf
找到类似下面的结构
<VirtualHost *:80>
ServerName myweb.com
ServerAlias www.myweb.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myweb.com
</VirtualHost>
修改成:
<VirtualHost *:80>
ServerName myweb.com
ServerAlias www.myweb.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/myweb.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =myweb.com [OR] RewriteCond %{SERVER_NAME} =www.myweb.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>