Nginx 作为代理服务与负载均衡
生活随笔
收集整理的這篇文章主要介紹了
Nginx 作为代理服务与负载均衡
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代理服務
代理一代為辦理(代理理財、代理收貨等等)
代理區別
區別在于代理的對象不一樣
正向代理代理的對象是客戶端
反向代理代理的對象是服務端
反向代理配置
server {listen 80;server_name localhost jeson.t.imooc.io;#charset koi8-r;access_log /var/log/nginx/test_proxy.access.log main;location / {root /usr/share/nginx/html;index index.html index.htm;}location ~ /test_proxy.html$ {proxy_pass http://127.0.0.1:8080;include proxy_params;} }# proxy_params 參數,同目錄下另一個文件保存proxy_redirect default;proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr;proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60;proxy_buffer_size 32k; proxy_buffering on; proxy_buffers 4 128k; proxy_busy_buffers_size 256k; proxy_max_temp_file_size 256k;
正向代理
server {listen 80;server_name localhost jeson.t.imooc.io;#charset koi8-r;access_log /var/log/nginx/test_proxy.access.log main;resolver 8.8.8.8;location / {proxy_pass http://$http_host$request_uri;} }負載均衡配置
upstream imooc {server 116.62.103.228:8001;server 116.62.103.228:8002;server 116.62.103.228:8003;}server {listen 80;server_name localhost jeson.t.imooc.io;access_log /var/log/nginx/test_proxy.access.log main;resolver 8.8.8.8;location / {proxy_pass http://imooc;include proxy_params;}}# 設置權重 upstream imooc {server 116.62.103.228:8001 down;server 116.62.103.228:8002 backup;server 116.62.103.228:8003 max_fails=1 fail_timeout=10s;}upstream imooc {server 116.62.103.228:8001;server 116.62.103.228:8002 weight=5;server 116.62.103.228:8003;}# IP hashupstream imooc {ip_hash;server 116.62.103.228:8001;server 116.62.103.228:8002;server 116.62.103.228:8003;}# uri hashupstream imooc {hash $request_uri;server 116.62.103.228:8001;server 116.62.103.228:8002;server 116.62.103.228:8003;}總結
以上是生活随笔為你收集整理的Nginx 作为代理服务与负载均衡的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nginx 静态资源WEB服务
- 下一篇: nginx 缓存设置