Last update at :2024-05-12,Edit by888u
Now more and more websites have enabled https access, which is safer and more friendly to search engines. Thirdly, there must be a large number of free SSL certificates on the market. For example, Tencent Cloud, Alibaba Cloud and Jingan all provide free certificates. Record here how to force http to redirect to https, to pave the way for 138vps.com to enable SSL in the future.
First, find the configuration file of your website. If you are using Jun Ge’s LNMP script, the path is /usr/local/nginx/conf/vhost/. If you installed nginx manually, the Centos 7 configuration file is usually in /etc/ nginx/conf.d/, the specific file depends on your own configuration at the time.
We need to first configure a server listening on port 443, and then make the following modifications to the server listening on port 80.
Normally, this server looks like this
listen 80;
server_name www.138vps.com;
.......
We add directly below these two lines
Method 1 (This is the oldest way of writing, not recommended)
rewrite ^(.*)$ https://$host$1 permanent;
Method 2 (more recommended)
return 301 https://$server_name$request_uri;
Method 3 If you have multiple domain names bound together, you can only set certain domain names to be forced to redirect
if ($host = "1.138vps.com") {
Rewrite ^/(.*)$ https://1.138vps.com permanent;
}
Method 4
Method 4 is different from the previous one. We don’t need another server listening on port 443, but put them all together, like this
listen 80;
listen 443 ssl http2;
server_name 138vps.com www.138vps.com;
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
Recommended site search: cheapest dual-line space, US PHP space, cheap virtual host foreign trade space Ministry of Industry and Information Technology registration inquiry, dynamic IP server, private server rental, virtual host agent, Hong Kong vps host, registered domain name Rent,
发表评论