美文网首页
ubuntu 设置http重定向为https

ubuntu 设置http重定向为https

作者: _Net_ | 来源:发表于2018-11-30 12:37 被阅读0次

1.开启重定向

sudo a2enmod rewrite

2.设置http端口重定向

打开 /etc/apache2/sites-available/000-default.conf ,

在 <\VirtualHost *:80><\VirtualHost> 标签内随便一个地方加入以下三行

RewriteEngine on

RewriteCond  %{HTTPS} !=on

RewriteRule  ^(.*)  https://%{SERVER_NAME}$1 [L,R]

或者在网站目录处新建.htaccess 

    RewriteEngine on

    RewriteBase /

    RewriteCond %{SERVER_PORT} !^443$

    RewriteRule ^.* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

3.最后重启

sudo service apache2 restart

相关文章

网友评论

      本文标题:ubuntu 设置http重定向为https

      本文链接:https://www.haomeiwen.com/subject/ptthcqtx.html