Nginx can realize http to https in many ways, and the implementation methods of various ways are listed below.
1、return 301
This is the new version of Nginx, recommended. Add a line to the Nginx 80 listening service: ### My other articles
return 301 https://$server_name$request_uri; #http跳转https
The complete configuration is as follows:
#管理端
server {
listen 10003;
server_name localhost;
try_files $uri $uri/ /index.html;
root /home/source/shop/manager/dist;
}
#管理端转发
server {
listen 80;
server_name admin-xxxxx.xxx.xxx;
return 301 https://$server_name$request_uri; #http跳转https
}
#管理端https
server {
listen 443 ssl;
server_name admin-xxxxx.xxx.xxx;
ssl_certificate ../cert/server.crt;
ssl_certificate_key ../cert/server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:10003;
}
}
2、rewrite
The old version of Nginx is not recommended. Change the line "#http jump https" to:
rewrite ^(.*)$ https://admin-xxxxx.xxx.xxx permanent;
or
rewrite ^(.*)$ https://$host$1 permanent;
3. 497 status code
Change the line "#http jump https" to:
error_page 497 https://$host$uri?$args;
4. Meta refresh
Write an index.html, the content is http to https jump:
index.html
<html>
<meta http-equiv=”refresh” content=”0; url=https://admin-xxxxx.xxx.xxx/”>
</html>
Then modify the Nginx configuration file, and change the line "#http to https" to:
error_page 404 https://admin-xxxxx.xxx.xxx
my website
A small mall made by myself, if you are interested, you can discuss technology with each other!
Byte cabinet: http://82.157.190.245/