Recently many people are more concerned about the application and setup of SSL certificate, Spring Brother technology blog recently also introduced some of the domestic free SSL certificate application process and more commonly used VPS site environment package How to install the configuration SSL certificate. Want a friend who needs to be able to successfully install an SSL certificate for their site. Here Chun brother for everyone to share several Nginx environment forced HTTP to HTTPS setting method.
First, please find the location of the Nginx configuration file:
In fact, the configuration file location is not very difficult to find, generally in the/nginx/conf/vhost/directory, file naming is generally "your domain name. conf". Here are a few common VPS Control Panel nginx configuration file location:
Wdlinux LANMP One-click installation package:/www/wdlinux/nginx-1.10.2/conf/vhost/Directory
Military Brother Lnmp One-click installation package:/usr/local/nginx/conf/vhost/Directory
Pagoda Linux Panel:/www/server/nginx/conf/vhost/directory
Second, the Nginx environment forced HTTP to HTTPS setting method:
Method One:
The following code is a copy of the past. No need to make any changes. Spring Brother Technology Blog recommended This method, very simple, after changing the real-time effect, do not restart the server.
if ($scheme = http) {return 301 https://$host $request_uri;}
Method Two:
The following code is a copy of the past. No need to make any changes.
if ($server _port =) {return 301 https://$host $request_uri;}
Method Three:
Note the following code to change the domain name into its own domain name.
if ($ssl _protocol = "") {return 301 https://$server _name$request_uri;} if ($host! = www.wn789.com) {return 301 $scheme://www.wn789.com$request_uri;}
Method Four:
The domain name in the following code should be changed to their own domain name, do not copy completely. It is also important to note that "listen 80;" is removed from the original code.
server {
Listen 80;
server_name Wn789.xin www.wn789.xin;
Rewrite ^ (. *) https://www.wn789.xin$1 permanent;
}
Method Five:
server {
Listen 80;
server_name wn789.xin www.wn789.xin www.789wn.com 789wn.comm;
Return 301 https://$server _name$request_uri;
}
Several setup methods of the Pagoda Linux Nginx http forced jump HTTPS