Home  >  Article  >  Operation and Maintenance  >  How to configure nginx proxy forwarding

How to configure nginx proxy forwarding

(*-*)浩
(*-*)浩Original
2019-07-15 12:02:1568834browse

How to configure nginx proxy forwarding

Nginx is a powerful server, you can configure multiple servers, a server is a server

server {
      listen       80;
      server_name  *.yourdomain.com;

   ....
}

The proxy forwarding is the location under the server Configure

server {
   // 服务器配置
   location  / {
   // ...... 代理配置
   }
}

Common Nginx proxy configuration

upstream my_server {                                                         
    server 10.0.0.2:8080;                                                
    keepalive 2000;
}
server {
    listen       80;                                                         
    server_name  10.0.0.1;                                               
    client_max_body_size 1024M;

    location /my/ {
        proxy_pass http://my_server/;
        proxy_set_header Host $host:$server_port;
    }
}

Through this configuration, access the nginx address http://10.0.0.1 :80/my requests will be forwarded to the my_server service address http://10.0.0.2:8080/

It should be noted that if configured as follows:

upstream my_server {                                                         
    server 10.0.0.2:8080;                                                
    keepalive 2000;
}
server {
    listen       80;                                                         
    server_name  10.0.0.1;                                               
    client_max_body_size 1024M;

    location /my/ {
        proxy_pass http://my_server;
        proxy_set_header Host $host:$server_port;
    }
}

Then, a request to access the nginx address http://10.0.0.1:80/my will be forwarded to the my_server service address http://10.0.0.2:8080/my. This is because if the proxy_pass parameter does not contain the path of the url, the path identified by the location pattern will be used as an absolute path.

For more Nginx related technical articles, please visit the Nginx usage tutorial column to learn!

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

Statement:
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