In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The content of this article mainly focuses on how Nginx redirects HTTP to HTTPS. The content of the article is clear and clear. It is very suitable for beginners to learn and is worth reading. Interested friends can follow the editor to read together. I hope you can get something through this article!
Nginx is a powerful redirect tool that can be easily configured to redirect unsecure or unencrypted HTTP network traffic on your system to encrypted and secure HTTPS network servers.
Nginx, pronounced "Engine x", is a free, open source, Linux-based, high-performance Web and reverse proxy server that manages and handles the largest load of website traffic on the Internet. Nginx is a powerful redirect tool that can be easily configured to redirect unsecure or unencrypted HTTP network traffic on your system to encrypted and secure HTTPS network servers. If you are a system administrator or developer, you should use the Nginx server frequently.
In this article, we will examine how to redirect Web traffic from HTTP to secure HTTPS in Nginx. The HTTP header is delivered in clear text string format, while HTTPS uses SSL/TLS to encrypt the communication between the client and server systems. Therefore, for many reasons, HTTPS should replace HTTP:
1. All data in both directions between the client and server is encrypted. However, if intercepted, no one can access sensitive information.
two。 When you use HTTPS, Google Chrome and other browsers will assume that your site domain is secure.
The 3.HTTPS version uses the HTTP/2 protocol to improve the performance of the website you specify.
4. If you serve your site domain through HTTPS, the site will rank higher on Google because it favors all sites protected by HTTPS.
5. For each site version, it is best to redirect the traffic HTTP in Nginx to HTTPS in a separate server block. It is also recommended to avoid redirecting traffic in the "if" direction, which can lead to abnormal server behavior.
Redirect all traffic from HTTP to HTTPS
Add the following changes to the Nginx configuration file to redirect all traffic from the HTTP to the HTTPS version:
Server {listen 80 default_server; server_name _; return 301 https://$host$request_uri;}
Below, we describe each of the above terms in detail:
Listen 80 default_server-this will instruct your system to capture all HTTP traffic on port 80
Server_name _-the matching order after receiving the request
Return 301 https://$host$request_uri-this tells your search engine to redirect it permanently. It specifies the variable $host to hold the domain name.
After you change the configuration settings, you need to reload the Nginx service on the system. Therefore, reload the Nginx service using the following command:
$sudo systemctl reload nginx
Redirects the HTTP of the specified domain name to HTTPS in Nginx
After you install the SSL certificate on your domain, you will have two server block options for this domain name. One block is used to listen on the HTTP version of port 80, and the second version is used to listen on the HTTPS of port 443. However, to redirect a website domain name from HTTP to HTTPS, you need to open the Nginx configuration. You can find this configuration file in the / etc/nginx/sites-available directory. If you don't find this file, you can search for it / etc/nginx/nginx./usr/local/nginx/conf or / usr/local/etc/nginx, and then make the following changes in the file:
Server {listen 80; server_name linuxmi.com www.linuxmi.com; return 301 https://linuxmi.com$request_uri;}
Let's walk through the above code line by line.
Listen 80-using port 80, the server listens for all incoming connections for the specified domain name.
Server_name linuxmi.com www.linuxmi.com-it specifies the domain name. Therefore, replace it with the domain name of the site you want to redirect.
Return 301 https://linuxmi.com$request_uri-moves traffic to the HTTPS version of the site.
The $request_uri variable is used for the complete original request URI, which also contains parameters.
Using the following methods, you can redirect traffic to the HTTPS www version to the non-www version of the site. For non-www and www versions, it is recommended that you create redirects in separate server blocks. Let's use an example to explain. If you want to redirect www HTTPS requests to a non-www version, you should follow the following configuration:
Server {listen 80; server_name linuxmi.com www.linuxmi.com; return 301 https://linuxmi.com$request_uri;} server {listen 443 ssl http2; server_name www.linuxmi.com; #. . . Other code return 301 https://linuxmi.com$request_uri;} server {listen 443 ssl http2; server_name linuxmi.com; #. . . Other code}
Replace the domain name with your domain name, such as www.linuxmi.com.
By changing the Nginx profile settings, you can easily redirect the specified domain name or all to HTTPS. The approach we mentioned in this article can make your site more secure by changing the user experience.
Thank you for your reading. I believe you have some understanding of "how Nginx redirects HTTP to HTTPS". Go ahead and practice it. If you want to know more about it, you can follow the website! The editor will continue to bring you better articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.