Current location: home page > Industry trends >Text content

Setting method of forced HTTPS jump in Apache / nginx server environment

Dazzle Yi Four years ago (2017-09-21) one thousand three hundred and sixty-nine two

  Although we have seen all kinds of news or so-called authoritative suggestions, websites are required to enable the HTTPS encryption format, but many large websites have not been started. Of course, the form of HTTPS encryption has advantages, but it can not force all websites to be enabled. For example, simple personal website, in fact, there is no need to use, but it will increase some costs and technical difficulties.


In the general web server environment, Apache or nginx environment driver will be adopted, and several scripts can be used to enforce the encryption of HTTP address. Of course, the premise is that we have deployed SSL certificates in the server.


First, Apache enforces the form of HTTPS


1. Add file location


Generally, it is a pseudo static file in the root directory of the website. If not, we need to create a. Htaccess file.


2. Force www jump

 RewriteEngine   On RewriteCond  % {HTTP_HOST}  !^ www.wanbk.net$   [NC] RewriteRule  ^ (.*)$   http://www.wanbk.net/ $1   [L,R=301] RewriteCond  % {SERVER_PORT}   eighty RewriteRule  ^ (.*)$   http://www.wanbk.net/ $1   [L,R=301]

3. Force non www jump

 RewriteEngine   On RewriteCond  % {HTTP_HOST}  !^ wanbk.net$   [NC] RewriteRule  ^ (.*)$   https://wanbk.net/ $1   [L,R=301] RewriteCond  % {SERVER_PORT}   eighty RewriteRule  ^ (.*)$   https://wanbk.net/ $1   [L,R=301]

Add it to the root directory. Htaccess file according to whether to use WWW or not, and take effect immediately.


Second, nginx forces HTTPS jump


1. Set file location


Generally, the. Conf file of the corresponding website domain name in the current server environment is added to the configuration environment.


2. Force www jump

 if   ($ssl_protocol  =  "")   {   return   three hundred and one   https://$host$request_uri;  } if   ($host  !=  www.wanbk.net)   {   return   three hundred and one  $ scheme://www.wanbk.net $request_uri;  }

3. Force non www jump

 if   ($ssl_protocol  =  "")   {   return   three hundred and one   https://$host$request_uri;  } if   ($host  !=  wanbk.net)   {   return   three hundred and one  $ scheme://wanbk.net $request_uri;  }

After setting, you need to restart nginx to take effect.

Related articles

 [windows] download around the client browser

[windows] download around the client browser

    Download around the browser of the excessive mother client, collected on the Internet, see that the forum is basically not speed limited client ah, this only needs to create a label folder in the browser, when downloading, click on the folder to download, and it is no trouble.   The code is this:      javascript:navigator.__ defineGetter__ ('platform',function(){return...

 [windows] system activated artifact: activation of win7, 8, 10 without networking

[windows] system activated artifact: activation of win7, 8, 10 without networking

  It is a tool that can activate Windows 10, windows 8.1, Windows 8, Windows 7 (enterprise / Professional), office 2013 (VL) and office 2010 (VL) without networking. It is a single executable green tool, which can be deleted directly without any residue on the system after use. This tool is an original tool to know your opponent and your friend. It is updated according to the user's requirements and feedback. The latest version fixes known bugs and is compatible with Windows XP to W

 [windows] ice point restore Chinese cracked version (with registration machine) can support 1TB hard disk

[windows] ice point restore Chinese cracked version (with registration machine) can support 1TB hard disk

  Used to freezing point all know, is a very good restore protection software, can be comparable to external disk restore device   Now it's hard to find a freezing point to support 1TB hard disk   Rar password: a5ah | size: 10.3M has been tested by security software, non-toxic, please feel free to download

 [PHP] WordPress Theme dux1.8 cracking free

[PHP] WordPress Theme dux1.8 cracking free

  I heard that Dux theme 1.8 was released last month, and the function of external chain thumbnail was added. I was very looking forward to it. Then I found out that Dux 1.8 cracked the unauthorized WordPress theme to try it out. Later, it was found that the function of external chain thumbnail was indeed added. However, it was not automatically recognized as the theme of Xiu, and it needs to be filled in the fixed link address, This has both advantages and disadvantages. The advantage is that you can customize the picture as the external chain thumbnail. The disadvantage is that if you change the non action external chain thumbnail, it will be gone. You need to reset it all

 Prevention of onion bitcoin blackmail virus one click fast shutdown port 135445

Prevention of onion bitcoin blackmail virus one click fast shutdown port 135445

RT is a piece of code, do not need to set your own, download and unzip, right-click to run as an administrator. The size of onion.rar: 568.0b has been tested by the safety software, and it is non-toxic. Please feel free to download

 Bitcoin blackmail virus is conquered - free recovery office tool with infection data!

Bitcoin blackmail virus is conquered - free recovery office tool with infection data!

  [heavyweight! Eternal blue "blackmail virus has been successfully conquered by a network security company in Sichuan, and the exclusive tool for free recovery of infection data has been released!] according to an article published by zuineijiang0832, the official wechat of the Information Office of Neijiang Municipal People's government, the" eternal blue "that has ravaged the Internet recently has been reported Blackmail virus has been a network security company in Sichuan - efficiency source information security technology company to successfully conquer! And released data recovery free products. Bitcoin ransomware. Rar size: 2.5m has been tested by security software. Please feel free to download

Comment list

 wxz
Four years ago (2017-09-22)

Yes, for my website, HTTPS is a burden on the server and on me

Dazzle Yi reply:
After all, it's just a personal blog. HTTPS is a trend
Four years ago (2017-09-22)

Comment

 visitor

Welcome to participate in the discussion. Please express your opinions and opinions here.