Web网站启用SSL证书,需要将网站的http访问通过301重定向指向到https,在类似宝塔面板的一些管理工具中已经可以对web容器进行操作,但是自行配置的web容器下需要单独配置。
- Apache
在apache站点的根目录下创建 .htaccess文件并增加以下配置
<IfModule mod_rewrite.c>RewriteEngine OnRewriteCond %{HTTP:From-Https} !^on$ [NC]RewriteRule ^(.*)$ https://www.weijing.co/$1 [R=301,L] # www.weijing.co对应修改为您自已的域名RewriteCond %{HTTP_HOST} !^www\.RewriteRule ^(.*)$ https://www.weijing.co$1 [R=301,L] # www.weijing.co对应修改为您自已的域名</IfModule>
- Nginx
在nginx.conf中增加以下内容:
server{listen 80;server_name weijing.co;rewrite ^(.*) https://www.weijing.co$1 permanent; #weijing.co 对应修改为您自已的域名}
- Tomcat
在web.xml最后一行</web-app>代码之前添加如下内容:
<security-constraint><!-- Authorization setting forSSL --><web-resource-collection ><web-resource-name >SSL</web-resource-name><url-pattern>/*</url-pattern></web-resource-collection><user-data-constraint><transport-guarantee>CONFIDENTIAL</transport-guarantee></user-data-constraint></security-constraint>
- IIS7
在web.config配置文件中增加以下内容。
<?xml version="1.0"encoding="UTF-8"?><configuration><system.webServer><rewrite><rules><rule name="301"stopProcessing="true"><match url="^(.*)$"ignoreCase="false"/><conditions logicalGrouping="MatchAll">#<add input="{HTTP_FROM_HTTPS}"pattern="^on$"negate="true"/><!-- <add input="{HTTPS}"pattern="^on$"negate="true"/> --></conditions><action type="Redirect"url="https://www.weijing.co/{R:1}"redirectType="Permanent"/> #替换www.weijing.co</rule></rules></rewrite></system.webServer></configuration>
- IIS6
将Rewrite的规则文件添加到httpd.conf中
RewriteEngine On
#RewriteCond %{HTTP:From-Https} !^on$ [NC]RewriteCond %{HTTPS} !^on$ [NC]RewriteRule ^(.*)$ https://www.weijing.co/$1 [R=301,L] # www.weijing.co对应修改为您自已的域名RewriteCond %{HTTP_HOST} !^www\.RewriteRule ^(.*)$ https://www.weijing.co$1 [R=301,L] # www.weijing.co对应修改为您自已的域名
