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 > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the illustration of the direction agent process through nginx, which is introduced in great detail through the sample code, which has a certain reference value for everyone's study or work. Friends who need it can refer to it.
Nginx implements directional proxy
1. What is nginx?
Nginx is a very lightweight HTTP server written by Russians. It is a high-performance HTTP and reverse proxy web server. It also provides IMAP/POP3/SMTP services. It is characterized by less memory and strong concurrency ability. in fact, the concurrency ability of nginx does perform well in the same type of web servers. Users who use nginx sites include: Baidu, JD.com, Sina, NetEase, Tencent, Taobao and so on.
two。 What is an agent?
In the proxy server, when the client sends the request, it will not send it directly to the destination host, but first send it to the proxy server. after receiving the request from the client, the proxy service sends it to the host and receives the data returned by the destination host. It is stored in the hard disk of the proxy server and then sent to the client.
For example, the people around us who want to rent a house
3. Situations where there is no agent
In the absence of an agent, the client and the nginx server are both clients, requesting the server between the clients, and the server responds directly to the client.
4. In the enterprise scenario, in the Internet request, the client is often unable to initiate the request directly to the server, so it is necessary to realize the communication between the client and the service.
Common patterns of 5.nginx proxy services
Nginx, as a proxy service, is summarized according to the application scenario. Agents are divided into forward agents and reverse agents.
6. Forward agent
Forward agent: client agent 1 > server:
Give a simple example of renting a house to the agent:
A (tenant) B (intermediary) C (landlord) A (client) wants to rent the house of C (server), but A (client) does not know that C (server) cannot rent. B (agent) knows that C (server) can rent the house, so you asked B (agent) to help rent the house. Ps: in this process, C (server) does not know A (client) only knows B (agent) C (server) and does not know that A (client) rents a house, only knows that the house is rented to B (agent).
The forward proxy, which is set up between the client and the target host, is only used to proxy Internet connection requests from the internal network. The client must specify a proxy server and send the http requests that should be sent directly to the Web server to the proxy server.
7. Reverse proxy
Reverse proxy: client 1 > proxy server reverse proxy also uses an example of renting a house: a (client) wants to rent a house, B (agent) rents the house to him. At this time, C (server) is actually the landlord. B (agent) is the intermediary who rented the house to A (client). In this process, A (client) does not know who the landlord of the house is, he may think that the house is B (agent).
The reverse proxy server is set up on the server side, which alleviates the workload of the server by buffering the frequently requested pages, forwards the client request to the target server on the internal network, and returns the result obtained from the server to the client requesting connection on the Internet. At this time, the proxy server behaves as a server with the target host.
8. Main applications of reverse proxy
Reverse proxies are now used on many large web sites. In addition to preventing the vicious attack of the external network on the intranet server and caching to reduce the pressure on the server and access security control, it can also carry out load balancing and distribute user requests to multiple servers.
Agent protocols that can be supported by 9.nginx agents
Http belongs to seven-layer application layer proxy hypertext transfer protocol https proxy http/https protocol TCP belongs to four-layer transport layer proxy tcp/dupxieywebsocket is used to develop proxy http1.1 long link communication protocol GRPC proxy go language remote invocation of POP/IMAP proxy mail sending and receiving protocol RTMP proxy streaming media, live broadcast
10.web01 configuration Agent
[root@web01 php] # vim / etc/nginx/conf.d/blog.drz.com.confserver {listen 80; server_name blog.drz.com; root / code/wordpress; index index.php index.html; access_log / var/log/nginx/blog.drz.com_access.log main; location ~\ .php ${fastcgi_pass 127.0.0.1 listen 9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params Server {listen 80; server_name blog.drz.com; location / {proxy_pass http://10.0.0.7; proxy_set_header HOST $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_connect_timeout 60s for editing wordpress Proxy_read_timeout 60s; proxy_send_timeout 60s; proxy_buffering on; proxy_buffer_size 8k; proxy_buffers 88k;}} root@lb01 ~] # nginx-tnginx: the configuration file / etc/nginx/nginx.conf syntax is oknginx: configuration file / etc/nginx/nginx.conf test is successful [root@lb01] # nginx-s reload
11. Add request header information sent to the back-end server
# if the value of HOST is www.oldboy.com when the user requests, then the proxy service will put the value of $remote_addr in the variable X-Real-IP like www.oldboy.comproxy_set_header Host $http_host;#, and the value of $remote_addr is the client's ipproxy_set_header X-Real-IP $remote_addr. # the client accesses the backend service through the proxy service, and the backend service records the real client address proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for through this variable
twelve。 TCP connection, response, return and other timeouts from the agent to the backend
/ / nginx agent connection timeout with backend server (proxy connection timeout) Syntax: proxy_connect_timeout time;Default: proxy_connect_timeout 60swiscontext: http, server, location / / nginx proxy waiting response time for backend server Syntax: proxy_read_timeout time;Default: proxy_read_timeout 60stransfercontext: http, server, location / / backend server data is returned to nginx proxy timeout Syntax: proxy_send_timeout time;Default: proxy_send_timeout 60s Context: http, server, location
13. Why use proxies
1) improve access speed because the data returned by the target host will be stored in the hard disk of the proxy server, so the next time the customer visits the same site data, it will be read directly from the hard disk of the proxy server, which plays the role of cache. especially for popular sites, it can significantly improve the speed of requests.
2) Firewall function since all client requests must access the remote site through the proxy server, a limit can be set on the proxy server to filter some unsafe information.
3) through the proxy server to access the inaccessible target site, there are many developed proxy servers on the Internet. When the access is limited, the client can access the target site through the unrestricted proxy server. Generally speaking, the wall-climbing browser we use is the use of a proxy server, although we can not go abroad, but can also directly access the external network.
14. Summary
The object of the forward proxy is the client, and the object of the reverse proxy for the client service is the server, which serves the server.
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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.