In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use nginx to achieve reverse proxy, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
What is a reverse proxy?
Proxy: through the configuration of the client, let a server (proxy server) proxy client, all the client's requests are handed over to the proxy server for processing.
Reverse proxy: use a server, proxy real server, when users access, is no longer to access the real server, but the proxy server.
Nginx can be used as a reverse proxy server:
We need to configure the reverse proxy rules in nginx in advance. Different requests should be handed over to different real servers for processing.
When the request arrives at the nginx,nginx, the request will be forwarded according to the defined rules, thus realizing the routing function.
The port problem we mentioned earlier can be solved by using reverse proxy, as shown in the figure:
Install and use installation
Installation is very simple, the nginx provided by pre-class materials can be decompressed directly, green installation-free, comfortable!
Download nginx: http://nginx.org/en/download.html
We install a nginx locally:
After decompression, the directory structure:
Conf: configuration directory
Contrib: third-party dependency
Html: default static resource directory, similar to tomcat's webapps
Logs: log directory
Nginx.exe: start the program. Double-click to run, but this is not recommended.
Reverse proxy configuration
Example:
Each server in nginx is a reverse proxy configuration and can have multiple server
Full configuration:
# user nobody;worker_processes 1 host events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; server {listen 80; server_name manage.leyou.com; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / {proxy_pass http://127.0.0.1:9001; proxy_connect_timeout 600; proxy_read_timeout 600;} server {listen 80 Server_name api.leyou.com; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / {proxy_pass http://127.0.0.1:10010; proxy_connect_timeout 600 Proxy_read_timeout 600;} use
Nginx can be started from the command line, manipulating commands:
Launch: start nginx.exe
Stop: nginx.exe-s stop
Reload: nginx.exe-s reload
The startup process flashes, and after a successful startup, there are two nginx processes in the task manager:
test
Start nginx, and then use the domain name to access the background management system: now that the domain name accesses the website, what is the flow in the middle?
The browser is ready to initiate a request to access http://mamage.leyou.com, but domain name resolution is required.
Priority is given to local domain name resolution. Because we modified the hosts, the resolution is successful and the address is 127.0.0.1.
The request is sent to the parsed ip and uses port 80 by default: the native nginx of http://127.0.0.1:80 has been listening on port 80, so the request is captured.
The reverse proxy rule is configured in nginx to proxy the manage.leyou.com to 127.0.0.1 9001, so the request is forwarded
The webpack server of the backend system listens on port 9001. The request is received and processed, and the response is returned to nginx after completion.
Nginx returns the results to the browser
The above content is how to use nginx to achieve reverse proxy, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.