常见问答

OV SSL证书申请,OVSSL证书部署,OV证书安装,OV SSL使用

您现在所在的位置首页 > 常见问答 > http如何自动切换跳转到https站点

http如何自动切换跳转到https站点

  有很多朋友下载好了ssl证书,但是在部署证书的时候有点不知所措,尤其是对于第一次部署SSL证书的用户,完全是两眼懵逼,可以说,部署ssl证书过程是艰难的,今天我们要说的就是,在部署网SSL证书后,怎样把http自动跳转到https。

 国内现在主流的Web服务器无外乎这几种,Tomcat、Apache、Nginx,相信站长们都应该或多或少接触过。下面,就跟着小编一起来看看这三者分别要怎么做,请摆好板凳,对号入座。

一、Apache服务器

我们需要找到Apache的配置文件httpd.conf,然后添加以下代码:

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]

以上代码是针对整站进行跳转,如果只需要跳转某个目录,则添加一下代码:

RewriteEngine on
RewriteBase /yourfolder
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

二、Nginx服务器

在配置80端口的文件中,添加以下代码:

server {
listen 80;
server_name localhost;
rewrite ^(.*)$ https://$host$1 permanent;
location / {
root html;
index index.html index.htm;
}

三、Tomcat服务器

这是三种服务器里面相对比较麻烦的,不过一步一步来,也是可以实现的。

首先,我们需要在服务器根目录下找到conf这个目录,找到其中server.xml文件这个文件,修改里面的redirectPort值为443,默认值一般为8443。

然后,还是在这个目录下找到web.xml文件,在尾部添加一下代码

<security-constraint>
<display-name>Auth</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/user/*</url-pattern>
<url-pattern>/main/index</url-pattern>
</web-resource-collection>
<user-data-constraint>
<description>SSL required</description>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

至此,三种服务器都可以实现http自动跳转到https,实现全站、局部、单页面的https化。