How to configure nginx reverse proxy

王林
Release: 2020-06-19 16:29:39
forward
22312 people have browsed it

How to configure nginx reverse proxy

Reverse proxy is the most commonly used server function in work and is often used to solve cross-domain problems. Let’s briefly introduce how to implement reverse proxy.

First enter the main configuration file of Nginx:

vim /etc/nginx/nginx.conf
Copy after login

(Recommended tutorial: nginx usage tutorial)

Then we go to the server block of the http module location/, add a line to redirect the default URL to the proxy_pass configuration of the largest learning website Bilibili:

How to configure nginx reverse proxy

Save and exit after changing, nginx -s reload Reload, enter the default URL, and now jump directly to station B, implementing a simple proxy.

In actual use, the request can be forwarded to another server on this machine, or it can be jumped to a service on a different port based on the access path.

For example, we listen to port 9001, and then perform reverse proxy for requests to access different paths:

Forward requests to access http://127.0.0.1:9001/edu to http:/ /127.0.0.1:8080

Forward the request to access http://127.0.0.1:9001/vod to http://127.0.0.1:8081

How to configure this , first open the main configuration file, and then add a server block under the http module:

server {
  listen 9001;
  server_name *.sherlocked93.club;

  location ~ /edu/ {
    proxy_pass http://127.0.0.1:8080;
  }
  
  location ~ /vod/ {
    proxy_pass http://127.0.0.1:8081;
  }
}
Copy after login

There are some other instructions for reverse proxy, you can learn about it:

1. proxy_set_header: in Change the request header information from the client before sending it to the backend server.

2. proxy_connect_timeout: Configure the timeout period for Nginx to try to establish a connection with the backend proxy server.

3. proxy_read_timeout: Configure Nginx to wait for the corresponding timeout after issuing a read request to the backend server group.

4. proxy_send_timeout: Configure Nginx to wait for the corresponding timeout after sending a write request to the backend server group.

5. proxy_redirect: used to modify the Location and Refresh in the response header returned by the back-end server.

The above is the detailed content of How to configure nginx reverse proxy. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!