基於https://www.cnblogs.com/Dfengshuo/p/11911406.html這個基礎上,在來補充下七層代理的配置方式。簡單理解下四層和七層協議負載的區別吧,四層是網路層,負載方式也就是IP+埠的方式負載,七層(應用層)協議的負載方式就是通過URL的方式來進行負載。這就是一 ...
基於https://www.cnblogs.com/Dfengshuo/p/11911406.html這個基礎上,在來補充下七層代理的配置方式。簡單理解下四層和七層協議負載的區別吧,四層是網路層,負載方式也就是IP+埠的方式負載,七層(應用層)協議的負載方式就是通過URL的方式來進行負載。這就是一個簡單通俗的理解吧。
nginx安裝方式再講四層的時候已經說過了,這裡就不再繼續安裝了。就直接上配置文件了
1 #user nobody; 2 worker_processes 1; 3 4 #error_log logs/error.log; 5 #error_log logs/error.log notice; 6 #error_log logs/error.log info; 7 #pid logs/nginx.pid; 8 events { 9 worker_connections 1024; 10 } 11 12 http { 13 include mime.types; 14 default_type application/octet-stream; 15 #access_log logs/access.log main; 16 sendfile on; 17 #tcp_nopush on; 18 #keepalive_timeout 0; 19 keepalive_timeout 65; 20 #gzip on; 21 server { 22 listen 80; #代理埠 23 server_name 10.156.128.251; #代理名稱 24 large_client_header_buffers 4 128k; 25 client_max_body_size 300m; 26 client_body_buffer_size 128k; 27 proxy_connect_timeout 600; 28 proxy_read_timeout 600; 29 proxy_send_timeout 600; 30 proxy_buffer_size 64k; 31 proxy_buffers 4 32k; 32 proxy_busy_buffers_size 64k; 33 proxy_temp_file_write_size 64k; 34 #charset koi8-r; 35 #access_log logs/host.access.log main; 36 location / { 37 # root html; 38 index index.html index.htm; 39 proxy_pass http://10.156.128.201/; #要跳轉server的IP 40 proxy_set_header X-Real-IP $remote_addr; 41 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 42 proxy_set_header Host $host:$server_port; 43 44 45 } 46 47 #error_page 404 /404.html; 48 49 # redirect server error pages to the static page /50x.html 50 # 51 error_page 500 502 503 504 /50x.html; 52 location = /50x.html { 53 root html; 54 } 55 56 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 57 # 58 #location ~ \.php$ { 59 # proxy_pass http://127.0.0.1; 60 #} 61 62 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 63 # 64 #location ~ \.php$ { 65 # root html; 66 # fastcgi_pass 127.0.0.1:9000; 67 # fastcgi_index index.php; 68 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 69 # include fastcgi_params; 70 #} 71 72 # deny access to .htaccess files, if Apache's document root 73 # concurs with nginx's one 74 # 75 #location ~ /\.ht { 76 # deny all; 77 #} 78 } 79 80 81 # another virtual host using mix of IP-, name-, and port-based configuration 82 # 83 #server { 84 # listen 8000; 85 # listen somename:8080; 86 # server_name somename alias another.alias; 87 88 # location / { 89 # root html; 90 # index index.html index.htm; 91 # } 92 #} 93 94 95 # HTTPS server 96 # 97 #server { 98 # listen 443 ssl; 99 # server_name localhost; 100 101 # ssl_certificate cert.pem; 102 # ssl_certificate_key cert.key; 103 104 # ssl_session_cache shared:SSL:1m; 105 # ssl_session_timeout 5m; 106 107 # ssl_ciphers HIGH:!aNULL:!MD5; 108 # ssl_prefer_server_ciphers on; 109 110 # location / { 111 # root html; 112 # index index.html index.htm; 113 # } 114 #} 115 116 }View Code
當然,筆者這份配置文件沒有進行優化,只是實現了代理效果,自己也可以根據需求進行優化