How to achieve reverse proxy and responsible balance between multiple nginx

1) nginx reverse proxy:
http {
    upstream routeadmin {
        ip_hash;
        server 127.0.0.1:9201 weight=5;
        server 127.0.0.1:9202 weight=5;
    }

 

    server {
        listen       80;
        server_name  localhost;

 

        location /route/admin {
            proxy_pass http://routeadmin;
        }
    }
}
 
2) to carry the front end nginx - Load 1:
http {
    include       mime.types;
    default_type  application/octet-stream;

    server {
        listen       9201;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /route/admin {
            proxy_pass http://127.0.0.1:9201/;
        }
    }
}
 
3) to carry the distal end nginx - Load 2:
http {
    include       mime.types;
    default_type  application/octet-stream;

    server {
        listen       9202;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /route/admin {
            proxy_pass http://127.0.0.1:9202/;
        }
    }
}
 
4) nginx built-in global variables
$ Args: This variable parameter row is equal to the request, with $ query_string
$ Content_length: Request Content-length header field.
$ Content_type: request header Content-Type field.
$ Document_root: current value specified in the instruction root request.
$ Host: the host request header field, otherwise the server name.
$ Http_user_agent: client agent information
$ Http_cookie: client cookie information
$ Limit_rate: This variable can limit the connection rate.
$ Request_method: action requested by the client, usually GET or POST.
$ Remote_addr: IP address of the client.
$ Remote_port: client port.
$ Remote_user: Username Auth Basic Module has passed validation.
$ Request_filename: the file path of the current request, requested by the instruction root URI or alias generated.
$ Scheme: HTTP method (such as http, https).
$ Server_protocol: protocol requests, usually HTTP / 1.0 or HTTP / 1.1.
$ Server_addr: server address, after the completion of a system call can determine this value.
$ Server_name: server name.
$ Server_port: request reaches the server's port number.
$ Request_uri: contains the original request URI parameters, it does not include the host name, such as: "/ foo / bar.php arg = baz?".
$ Uri: with no request parameters of the current URI, $ uri does not contain a host name, such as "/foo/bar.html".
$ Document_uri: given $ uri homologous.
 
 

Guess you like

Origin www.cnblogs.com/zftylj/p/nginx04.html