https is a safer version of http. Automatically jumping to https through http can make it easier for users to use the web.
There are several ways to complete the jump:
1. Open the http and https servers and let http jump to https
server { listen 80; listen [::]:80; return 301 https://$host$request_uri; } server { listen 443 ssl; listen [::]:443 ssl; ssl_certificate certificate_file_path; ssl_certificate_key certificate_key_file_path; ... }
2. Do not open http server, complete the jump directly in the https server, the following three methods can be used
server { if ($server_port = 80 ) #if ($scheme = http ) #if ($ssl_protocol = "") { return 301 https://$host$request_uri; } listen 443 ssl; listen [::]:443 ssl; ssl_certificate certificate_file_path; ssl_certificate_key certificate_key_file_path; ... }
The above is the detailed content of How does Nginx automatically jump from http to https?. For more information, please follow other related articles on the PHP Chinese website!