多個nginx之間如何實現反向代理和負責均衡


1)nginx反向代理:
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)以nginx承載前端-負載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)以nginx承載前端-負載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內置全局變量
$args :這個變量等於請求行中的參數,同$query_string
$content_length : 請求頭中的Content-length字段。
$content_type : 請求頭中的Content-Type字段。
$document_root : 當前請求在root指令中指定的值。
$host : 請求主機頭字段,否則為服務器名稱。
$http_user_agent : 客戶端agent信息
$http_cookie : 客戶端cookie信息
$limit_rate : 這個變量可以限制連接速率。
$request_method : 客戶端請求的動作,通常為GET或POST。
$remote_addr : 客戶端的IP地址。
$remote_port : 客戶端的端口。
$remote_user : 已經經過Auth Basic Module驗證的用戶名。
$request_filename : 當前請求的文件路徑,由root或alias指令與URI請求生成。
$scheme : HTTP方法(如http,https)。
$server_protocol : 請求使用的協議,通常是HTTP/1.0或HTTP/1.1。
$server_addr : 服務器地址,在完成一次系統調用后可以確定這個值。
$server_name : 服務器名稱。
$server_port : 請求到達服務器的端口號。
$request_uri : 包含請求參數的原始URI,不包含主機名,如:”/foo/bar.php?arg=baz”。
$uri : 不帶請求參數的當前URI,$uri不包含主機名,如”/foo/bar.html”。
$document_uri : 與$uri相同。
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM