Nginx サーバーの構成手順:
書き換え関数、プロキシ関数
書き換え関数
バックエンドサーバーグループの設定手順
アップストリーム命令
アップストリーム命令はバックエンドサーバーグループを設定するための主な命令です
<code>upstream name {<span>...</span>} </code>
リクエストはラウンドロビン(RR)に従ってスケジュールされます) ポリシー順序選択サーバー処理
server
server ディレクティブは、グループ内のサーバーを設定するために使用されます
<code>server address [<span>params</span>];</code>
注:
ip_hash コマンドは、システム全体で、フロントエンド サーバーである必要があり、クライアント アドレスは、
<code>keepalive connections;</code>
<code>resolver address <span>...</span> [valid=time];</code>
<code>resolve_timeout <span>time</span>;</code>
<code>proxy_pass <span>URL</span>;</code>
<code>proxy_pass <span>URL</span>;</code>
<code>proxy<span>\_</span>hide_header field</code>
<code>proxy<span>\_</span>hide_header field</code>
<code>proxy<span>\_</span>hide_header field</code>
<code><span>...</span> upstream backend { server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location / { proxy_pass http://backend; proxy_set_header Host $host; <span>...</span> } <span>...</span> }</code>
<code><span>...</span> upstream backend { server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span> weight=<span>5</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span> weight=<span>2</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location / { proxy_pass http://backend; proxy_set_header Host $host; <span>...</span> } <span>...</span> }</code>
<code><span>...</span> upstream videobackend { server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } upstream filebackend { server <span>192.168</span><span>.1</span><span>.5</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.6</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.7</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location /video/ { proxy_pass http://videobackend; proxy_set_header Host $host; <span>...</span> } location /file/ { proxy_pass http://filebackend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; <span>...</span> } <span>...</span> }</code>
<code><span>...</span> upstream bbsbackend{ server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span> weight=<span>2</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span> weight=<span>2</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } upstream homebackend { server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.5</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.6</span>:<span>80</span>; } server { listen <span>80</span>; server_name home.mysite.name; index index.html index.htm; location / { proxy_pass http://homebackend; proxy_set_header Host $host; <span>...</span> } <span>...</span> } server { listen <span>81</span>; server_name bbs.mysite.name; index index.html index.htm; location / { proxy_pass http://bbsbackend; proxy_set_header Host $host; <span>...</span> } <span>...</span> }</code>
<code><span>...</span> upstream backend{ server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location /file/ { rewrite ^(/file/.*)/media/(.*)\.*$ $<span>1</span>/mp3/$<span>2.</span>mp3 last; } location / { proxy_pass http://backend; proxy_set_header Host $host; <span>...</span> } }</code>