How does Nginx automatically jump from http to https?

PHPz
Release: 2023-05-12 14:49:06
forward
3958 people have browsed it

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;

    ...

}
Copy after login

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;

    ...

}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template