Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Record the process of configuring http to jump to https

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The company recently launched a data operation platform, which will display all the data in the form of web interface. This project is the focus of one of our managers. After the platform module is deployed and started, bind the extranet IP of the platform server to the domain name alkaid.lechange.com, type https://alkaid.lechange.com in the browser, and you will see the web page written by the front-end colleagues.

However, our domineering manager said that this would not work, saying that he wanted more requirements, higher standards and better experience, so he put forward a requirement that he would automatically jump to https://alkaid.lechange.com when entering alkaid.lechange.com.

In that case, let's add a few configuration files to the original nginx.conf on nginx:

# include upstream include upstream.conf; # include servers include alkaid.conf; include alkaid-https.conf

So when you execute nginx.conf, you will call upstream.conf, alkaid.conf, and alkaid-https.conf. Let's take a look at these three files.

The alkaid.conf file is as follows:

Server {listen 80; server_name * .lechange.com; proxy_buffering off; location / {rewrite ^ / https://alkaid.lechange.com permanent; client_max_body_size 100m;}}

Here we listen to port 80, the following "client_max_body_size 100m" is used to set the size of nginx+php uploaded files, here is 100m, this can be written into nginx.conf, if you are interested in uploading files, you can see http://www.cnblogs.com/zhwl/archive/2012/09/18/2690714.html.

Let's take a look at alkaid-https.conf, as follows:

Server {listen 10000; server_name * .lechange.com; proxy_buffering off; location / {proxy_pass http://alkaid_backend; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off }}

Port 10000 is monitored here, and location is written as http://alkaid_backend. What is this alkaid_backend?

At this point, we need to take a look at upstream.conf, which reads:

Upstream alkaid_backend {server X.X.X.XpurJQK; check interval=5000 rise=2 fall=5 timeout=1000 type=tcp default_down=false;}

X.X.X.X is the private network IP address of the module server, and JQK is the module port of the module server, which should be written here according to the actual situation. It can be seen that alkaid_backend corresponds to the module server and its port, and the following is the check interval and so on.

Now we start nginx, then bind the public network address of nginx to the domain name alkaid.lechange.com, type alkaid.lechange.com in the browser, and we will achieve the goal of automatic redirection!

Here I would like to add that we have set 80 configuration files and 443 files here, but the forwarding process of these two files is different: the alkaid-https.conf file redirects the 443 request to the service of the platform module server, while the alkaid.conf file redirects all requests coming in from port 80 directly to https://alkaid.lechange.com permanently. However, the alkaid.lechange.com will still access the services of the platform module server, which means that the alkaid.conf file is redirected one more step.

Finally, if you think this article is helpful for your promotion and salary increase to marry Bai Fumei, then please do not hesitate to sponsor, swipe the QR code below, and sponsor me to continue to write more excellent blog posts!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report