Implementation of multiple port mapping for nginx reverse proxy

  • 2020-05-17 07:47:57
  • OfStack

Code interpretation

1.1 http: www baidu. test. com default is 80, access to "/" using a reverse proxy, then access to the local 8083;

1.2 8083 represents the local front-end project access address, the front-end needs to access the background data, "/", continue to proxy to the background address 9803;

1.3 in this way, multiple port access can be completed as long as port 80 is opened.

1.4 the root configuration can be either an absolute or a relative path.


 server {
    listen    80;
    server_name www.baidu.test.com;# The domain name you want to fill in is separated by commas 
    location / {
      proxy_pass http://localhost:8083; 
      proxy_set_header Host $host; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      root  /app/esop_web/esopschool;
      index index.html;
      try_files $uri $uri/ /index.html;
    }
    location /rest{
      proxy_pass http://localhost:9803; 
      proxy_set_header  Host  $host; 
      proxy_set_header  X-Real-IP  $remote_addr; 
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
    }
  }

Related articles: