How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS

王林
Release: 2023-09-26 11:19:41
Original
1674 people have browsed it

如何使用Nginx Proxy Manager实现HTTP到HTTPS的自动跳转

How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS

With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt transmission data to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and Nginx Proxy Manager is a simple and easy-to-use proxy manager based on Nginx, which can realize automatic jump from HTTP to HTTPS. This article will introduce how to use Nginx Proxy Manager to implement this function and provide specific code examples.

Step 1: Install Nginx Proxy Manager

First, you need to install Nginx Proxy Manager on the server. It can be installed through the following command:

$ git clone https://github.com/jc21/nginx-proxy-manager.git
$ cd nginx-proxy-manager
$ docker-compose up -d
Copy after login

This will start a Docker container on the server, which contains the Nginx server and Nginx Proxy Manager management interface.

Step 2: Configure the domain name and SSL certificate

Enter the Nginx Proxy Manager management interface, access the server's IP address through the browser, and log in using the default username and password.

In the left navigation bar of the interface, select "Proxy Hosts" and then click the "Add Host" button. In the pop-up dialog box, enter the domain name information and SSL certificate related information. Make sure the "Force SSL" option is selected to force HTTPS to be enabled.

Step 3: Set automatic jump from HTTP to HTTPS

In the Nginx Proxy Manager management interface, select the "Proxy Hosts" option and find the host just added. Click the name of the host to enter the configuration page.

At the top of the configuration page, find the "SSL Proxy" option. In the "Redirects" drop-down menu, select "Redirect All Traffic to HTTPS."

Click the "Save" button at the bottom of the page to save the configuration and apply the changes.

Step 4: Verify that the configuration is effective

Restart the Nginx Proxy Manager container to make the configuration take effect. You can restart the container through the following command:

$ cd nginx-proxy-manager
$ docker-compose restart
Copy after login

Then, access the configured domain name through the browser. If everything is normal, the access will automatically jump to the HTTPS protocol, and a lock icon will be displayed in the browser address bar. Indicates the connection is secure.

Code example:

server {
    listen 80;
    server_name example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com;
    
    ssl_certificate /etc/nginx/ssl/cert.pem;
    ssl_certificate_key /etc/nginx/ssl/key.pem;
    
    # other configuration...
}
Copy after login

In the above example, the first server block listens on port 80 and returns a 301 redirect to HTTPS via the return 301 directive. The second server block listens on port 443 and configures the path to the SSL certificate, and can add other configurations as needed.

Summary:

By using Nginx Proxy Manager, we can easily realize automatic jump from HTTP to HTTPS. You only need to select the corresponding option in the configuration interface to complete the relevant configuration. Nginx Proxy Manager not only simplifies the deployment of HTTPS protocol, but also provides a friendly management interface to facilitate users to perform related operations. I hope this article can help everyone understand and use Nginx Proxy Manager.

The above is the detailed content of How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!