Nginx HTTP HTTPS Configuration

For the security of data transmission and to prevent web pages from being maliciously tampered with, most websites are now configured with https.

How to ensure that users access through https?

If nginx is useful, we can configure forced redirection.

Add in the nginx configuration:

server {

listen 80;
listen 443 ssl;
server_name www.imcati.com;
root /usr/share/nginx/html;
if ($server_port = 80) {return 301 https://$server_name$request_uri;}
# return 301 https:// $server_name$request_uri; can be written as rewrite ^/(.*)$
https://$server_name$1;
 .... .. 

location / {
index index.html;
}
}

Access test:

< p>share picture

We can When you see the content of the http request, the https finally requested, so as to verify that the configuration is successful.

server {

listen 80;
listen 443 ssl;
server_name www.imcati.com;
root /usr/share/nginx/html;
if ($server_port = 80) {return 301 https://$server_name$request_uri;}
# return 301 https:// $server_name$request_uri; can be written as rewrite ^/(.*)$
https://$server_name$1;
 .... .. 

location / {
index index.html;
}
}

Leave a Comment

Your email address will not be published.