Home Website Building Knowledge Standard Post

Standard Post

LNMP One-Click Package Nginx 301 Force Redirect to HTTPS Tutorial

If the website has enabled both HTTPS and HTTP protocols, for SEO and consistency, HTTP access is redirected to HTTPS. If you are using the LNMP one-click package or nginx, you can achieve a 301 redirect to HTTPS using the following method. Open your website's configuration file, for example, Naibabiji's configuration file is at /usr/…

Updated on November 1, 2019 About 2 minutes read
LNMP一键包nginx 301强制跳转到https教程

If a website enables both HTTPS and HTTP protocols, for SEO and consistency considerations, HTTP access will be redirected to HTTPS. If you are using the LNMP one-click package or nginx, you can achieve a 301 redirect to HTTPS using the method below.

Open your website's configuration file, for example, Naibabiji's configuration file is at /usr/local/nginx/conf/vhost/blog.naibabiji.com.conf

After opening, the format is roughly as follows

server {
listen 80;
server_name blog.naibabiji.com;
省略其他配置
}
server {
listen 443 ssl;
server_name blog.naibabiji.com;
省略其他配置
}

What you need to modify is the content of the line `listen 80;` (80 is HTTP, 443 is HTTPS).

server {
listen 80;
server_name blog.naibabiji.com;
return 301 https://blog.naibabiji.com$request_uri;
}
server {
listen 443 ssl;
server_name blog.naibabiji.com;
省略其他配置
}

Then save and restart nginx to achieve HTTP access redirecting to HTTPS.

5/5 - (1 vote)
Previous Method One for KeePass to Automatically Fill Passwords in Chrome Browser Continue reading content around the same timeline. Next Method Two for KeePass to Automatically Fill Passwords in Chrome Browser View the next related tutorial or experience.

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: