Nginx environment forces http 301 to jump to https settings record

888u

Last update at :2024-06-15,Edit by888u

Nowadays, more and more websites are starting to enable SSL certificates, which is also a trend. Snail is also considering whether to start it, but considering that many of the page themes are set manually, it would be troublesome to switch over, so I am considering taking some time to change the theme recently, and then enable the SSL certificate when the time is right. After upgrading Firefox after the year, I saw that some non-HTTPS websites also have prompts in the address bar, so this is also a trend, but it is not absolute. After all, ordinary websites are not interactive and there is no need for HTTPS.

If we switch from http to https, we will definitely need the uniqueness of the address, and we need to set up a 301 jump to force https. Here is a simple technical document to record, and compile a few script codes for Nginx to implement forced http jump to https. In the future You can copy and use it directly when necessary.

First, Nginx configuration file modification address

/usr/local/nginx/conf/vhost

Generally, the one-click packages we commonly use or the ones we configure ourselves may be slightly different. We need to find the .conf configuration file where the current website is located. Remember to back it up before modifying it to avoid making mistakes.

Second, several common 301 jump methods available

First:

if ($scheme = http ) {return 301 https://$host$request_uri;}

Second:

server_name laobuluo.com ;rewrite ^(.*) https://laobuluo.com$1 permanent

Replace the domain name with your own domain name.

Third:

if ($server_port = 80 ) {return 301 https://$host$request_uri;}

This is similar to the first one.

Fourth:

server_name laobuluo.com ;return 301 https://$server_name$request_uri;

Just change the domain name to your own.

Finally, after we modify and replace, we need to restart nginx for it to take effect.

Recommended site searches: European servers, cm domain name registration, US vps host, domain name registration price, domain name registration fee, check ip, ip proxy server, high-defense US server, Korean independent server, US server website,

Nginx environment forces http 301 to jump to https settings record

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码