SongShuA

SongShuA

胸中梦黄粱,手握自在心 一个充满想法的网络安全从业人员 A person with dreams in their heart and the ability to control their own destiny, who is a creative professional in the field of cybersecurity.
github

Initial order single domain single port multiple service web

Recently, I encountered this situation several times. There is a domain and a port, but there are files with different extensions.

At first, I thought of port reuse. Although I haven't actually used it, I know from the term that it should work. But then I thought, most developers or operations personnel are not technically strong, so it is unlikely that they will use port reuse. It wasn't until yesterday that a master in a group posted a screenshot of an article mentioning this situation and said it might be using reverse proxy technology. That's when I suddenly realized.

Reverse Proxy

Most operations personnel are familiar with this, as it is a basic type of VPN technology. Previously, I only had a rough idea of this, so this was a good opportunity for me to learn.

First, let's talk about the concept of reverse proxy, and I'll show you two pictures.

Forward Proxy

Reverse Proxy

These two pictures are already very clear, if you still don't understand. In simple terms, a regular proxy (forward proxy) turns the user into a proxy server to access resources. Reverse proxy is when the server brings the resources to the user for access. One is to let the user go out, and the other is to let the resources come in.

Speaking of reverse proxy, we have to mention Nginx. This is commonly used for reverse proxy servers, although Apache can also be used, but it seems that not many people use it.

The reverse proxy function is set in the Nginx configuration file. Nginx/conf/nginx.conf

The content of this file can be understood with this structure:

http {
	server {
	
	}
}

"Http" refers to HTTP server-related settings, and "server" refers to the enabled service function modules. So we need to make the settings within the "server" section.

image-20210813203043769

As shown in the image.

The server listens on port 80.

The service identification name is the bound domain name.

"Location" is the local-related settings, followed by a path or regular expression. Here, I have written two rules to determine the file extensions.

So the function of this configuration is: when accessing the server with www.ttt.com, it checks the file extension. If it is html, it reverse proxies to service on port 888, and if it is txt, it reverse proxies to service on port 889. (The two ports are used to differentiate between different websites, because I don't actually have two servers, so I have to differentiate them using two ports on one server.)

Location Configuration Rules: https://juejin.cn/post/6908623305129852942

Master y4er also mentioned that it could be a local web service plus a reverse proxy. This approach might also achieve this functionality, but I still have doubts. Because there seems to be some conflicts in the configuration file. The web service should be set directly at the http layer, while the reverse proxy is set at the server layer. Let's not talk about priority and overlap for now. The rules in "location" can only take effect at this layer, and it should not work at the higher layer.

Of course, I didn't try it further and I'm not sure, it's just speculation.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.