Inscription:
The problem is mainly because the environment where I work often needs to bind hosts. Sometimes I need to bind more than 10, and it is very troublesome to switch between multiple environments. Later, I found that some colleagues used the proxy method to bind them uniformly. I really think it is a recovery It’s a good way, so I conducted a more detailed investigation on proxy tools, and wrote this article. The key problem solved in this article is how to bind hosts through a proxy.
The following article is my personal understanding, please correct me if there are any deficiencies or mistakes, thank you!
The word agent is believed to be familiar to everyone, and students who are familiar with overpassing the wall must be familiar with it. Hehe, this article does not explain how to find a ladder. I believe everyone has their own way of crossing the sea.
To learn a proxy, you must first clarify two concepts: forward proxy/reverse proxy. There are a lot of information about the forward and reverse instructions on Google.
Simply understand that the so-called forward is an access from the inside to the outside, and the so-called reverse is an access from the outside to the inside. Forward and reverse are relative concepts.
To put it simply, we know that nginx is a very good reverse proxy tool. Many major websites are using nginx as a reverse proxy. For external users accessing the website An open nginx reverse proxy server, while the generation of the page is done through the internal web service, and the implementation of the service may vary widely.
The forward proxy is our general meaning of overcoming the wall, accessing through the proxy, and then returning the result from the proxy. This is the principle.
So what is relative? Compared with internal services, nginx is a reverse proxy, which accepts user requests; and relative to users, it is a forward proxy, which acts as a proxy for users to request. After understanding this relative process, we can actually make nginx our forward proxy tool, and regard the outside network as the entire backend providing services to us.
Reprinted above.
When accessed via http://www.XXX.com,
In fact, the agent arrived at http://192.168.xxx.yyy:8080/Action/
server {
listen
80;
server_name www.XXX.com;
# DNS domain name through Windows hosts configuration
location / {
proxy_pass
http://192.168.xxx.yyy:8080/Action/;
Proxy_redirect off;
proxy_set_headerHost
$host;
proxy_set_header
X-Real-IP $remote_addr;
proxy_set_header
X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Reverse proxy: That is, the above port 80 only listens to port 80 in the access from outside to inside.
The role of the Hosts file in Windows:
Enter the domain name in the browser, such as: www.sina.com.
Windows will first check whether the mapping of this domain name already exists in the hosts file. If it does not exist, it will resolve the domain name through the dns domain name resolution server to obtain the corresponding Sina IP address. Then use this ip address to access Sina.com.
The purpose is one: to get the IP address.
Specific reference: http://wenku.baidu.com/view/180738bfc77da26925c5b0c4.html
After changing the configuration file of nginx, when you go to visit the browser, at this time, the browser has a cache, and the configuration of nginx may not be applied immediately, even if nginx
Restart does not help, so you must clear the browser cache before executing it.
server {
listen 80;
server_name www.163.com;# DNS domain name through Windows hosts configuration
Location /
{
proxy_pass http://sina.com;
proxy_redirect off;
}
}
server {
listen 80;
server_name www.baidu.com;# DNS domain name through Windows hosts configuration
Location /
{
proxy_pass http://www.google.com;
proxy_redirect off;
}
}
Result: Entering www.163.com will jump to Sina.com, and entering www.baidu.com will jump to the google homepage.
Mapping relationship in hosts:
127.0.0.1 www.163.com
127.0.0.1 www.baidu.com