Javaの基本的なスキルの実際の戦い—Nginxのさまざまなアプリケーションシナリオの構成(直接コピーおよび変更できます)

Nginxフォワードプロキシ

server {
	listen 8090;
	server_name  www.gps.com;
	location / {
			resolver 218.85.157.99 218.85.152.99;
			resolver_timeout 30s;
			proxy_pass http://$host$request_uri;
	}
	access_log  /data/httplogs/proxy-$host-aceess.log;      
}

テスト:
http //www.gps.com 8090

Resolverコマンドの
構文:resolveraddress…[valid = time];
デフォルト値:
—構成セクション:http、server、locationDNS
サーバーのIPアドレスを構成します。複数を指定して、ポーリングモードでそれらを要求できます。
Nginxは分析結果をキャッシュします。デフォルトでは、キャッシュ時間は名前解決応答のTTLフィールドの値であり、有効なパラメーターを使用して変更できます。

resolver_timeout命令
構文:resolver_timeout time;
デフォルト値:resolver_timeout 30s;
構成セクション:http、サーバー、ロケーション
解決タイムアウト時間。

Nginxリバースプロキシ

1.通常のポーリング

server {
        listen       80;
        server_name  www.123.com;

        location / {
            proxy_pass http://127.0.0.1:8080;
            index  index.html index.htm index.jsp;
        }
    }

ポート80でリッスンし、アクセスドメイン名はwww.123.comです。ポート番号が追加されていない場合、ポート80がデフォルトであるため、ドメイン名にアクセスすると、パス127.0.0.1:8080にジャンプします。 。

nginxロードバランシング

upstream OrdinaryPolling {
    server 127.0.0.1:8080;
    server 127.0.0.1:8081;
    }
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://OrdinaryPolling;
            index  index.html index.htm index.jsp;

        }
    }

2.比例加重ポーリングに基づく

upstream OrdinaryPolling {
    server 127.0.0.1:8080 weight=5;
    server 127.0.0.1:8081 weight=2;
    }
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://OrdinaryPolling;
            index  index.html index.htm index.jsp;

        }
    }

IPに基づくルート負荷

upstream OrdinaryPolling {
    ip_hash;
    server 127.0.0.1:8080 weight=5;
    server 127.0.0.1:8081 weight=2;
    }
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://OrdinaryPolling;
            index  index.html index.htm index.jsp;

        }
    }

3.サーバーの応答時間に基づく負荷分散

upstream OrdinaryPolling {
    server 127.0.0.1:8080 weight=5;
    server 127.0.0.1:8081 weight=2;
    fair;
    }
    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://OrdinaryPolling;
            index  index.html index.htm index.jsp;

        }
    }

4.さまざまなドメイン名の負荷分散を実現します

upstream wordbackend {
    server 127.0.0.1:8080;
    server 127.0.0.1:8081;
    }

    upstream pptbackend {
    server 127.0.0.1:8082;
    server 127.0.0.1:8083;
    }

    server {
        listen       80;
        server_name  localhost;

        location /word/ {
            proxy_pass http://wordbackend;
            index  index.html index.htm index.jsp;

        }
    location /ppt/ {
            proxy_pass http://pptbackend;
            index  index.html index.htm index.jsp;

        }
    }

静的リソースサーバー

server {

       listen 8300;
       server_name localhost;

       location / {
          root /home/testStatic;
           access_log   on;
               autoindex  on;
       }

 }

server_name:ドメイン名

リッスン:ポート

ルート:静的ページのパス

おすすめ

転載: blog.csdn.net/Coder_Boy_/article/details/111503753