Nginx反向代理和負(fù)載均衡部署方法

本篇內(nèi)容介紹了“Nginx反向代理和負(fù)載均衡部署方法”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

公司專注于為企業(yè)提供做網(wǎng)站、成都網(wǎng)站建設(shè)、微信公眾號(hào)開發(fā)、商城開發(fā),重慶小程序開發(fā),軟件定制開發(fā)等一站式互聯(lián)網(wǎng)企業(yè)服務(wù)。憑借多年豐富的經(jīng)驗(yàn),我們會(huì)仔細(xì)了解各客戶的需求而做出多方面的分析、設(shè)計(jì)、整合,為客戶設(shè)計(jì)出具風(fēng)格及創(chuàng)意性的商業(yè)解決方案,創(chuàng)新互聯(lián)更提供一系列網(wǎng)站制作和網(wǎng)站推廣的服務(wù)。

nginx反向代理與負(fù)載均衡

  1. upstream proxy.test.com {

  2.              #ip_hash;

  3.              server 192.168.6.119:9090;

  4.              server 192.168.6.119:8090;

  5.          }

  6. server {

  7.         listen 80;

  8.         server_name proxy.test.com;

  9.         location / {

  10.           proxy_set_header Host $host;

  11.           proxy_set_header X-Real-IP $remote_addr;

  12.           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  13.  

  14.              #禁用緩存

  15.              proxy_buffering off;

  16.  

  17.              #反向代理的地址

  18.              proxy_pass http://proxy.test.com;

  19.         }

  20.     }

[root@node3 vhost]# curl proxy.test.com
119
[root@node3 vhost]# curl proxy.test.com
nginx2
[root@node3 vhost]# curl proxy.test.com
119
[root@node3 vhost]# curl proxy.test.com
nginx2

線上某機(jī)器舉例:反向代理和負(fù)載均衡

  1. upstream oc_haodai_com {

  2.         server 192.168.1.37:8080 weight=2 max_fails=2 fail_timeout=30s;

  3.       # server 192.168.1.38:8080 weight=2 max_fails=2 fail_timeout=30s;

  4.       #server 192.168.1.39:8080 weight=2 max_fails=2 fail_timeout=30s;

  5. }

  6. server {

  7.         listen 443;    ###https的默認(rèn)端口  http是80

  8.     

  9.         server_name oc.haodai.com;

  10.         ssl on;

  11.          ssl_certificate /usr/local/nginx1.8/conf/haodai.com.crt;

  12.          ssl_certificate_key /usr/local/nginx1.8/conf/haodai.com.key;

  13.         location / {

  14.                 proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header;

  15.                 proxy_set_header Host $host;

  16.                 proxy_set_header X-Real-IP $remote_addr;

  17.                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  18.                 #session_sticky_hide_cookie upstream=account.free4lab.com;

  19.                 proxy_pass http://oc_haodai_com;

  20.         }

  21.     access_log /home/wwwlogs/oc.haodai.com.proxy.log access;

  22. }

  23. server {

  24.         listen 80;

  25.         server_name oc.haodai.com;

  26.         location / {

  27.                 proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header;

  28.                 proxy_set_header Host $host;

  29.                 proxy_set_header X-Real-IP $remote_addr;

  30.                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  31.                 #session_sticky_hide_cookie upstream=account.free4lab.com;

  32.                 proxy_pass http://oc_haodai_com;

  33.         }

  34. }


37.38.39上配置文件

  1. [root@order_web04 vhost]# more oc.haodai.com.conf

  2. server {

  3.         listen       8080;

  4.         server_name  oc.haodai.com;

  5.         index index.html index.htm index.php;

  6.         root  /home/wwwroot/order_center;

  7.         access_log /home/wwwlogs/oc.haodai.com.log access;

  8.         location / {

  9.             index index.php;

  10.             if ( !-e $request_filename){

  11.                 rewrite ^/(.*)$ /index.php?s=$1 last;

  12.                 break;

  13.             }

  14.         }

  15.         location ^~ /.git {

  16.             return 403;

  17.         }

  18.         location ~ /Common/sh/.*\.(php|php5|sh|py|pl)$ {

  19.             deny all;

  20.         }

  21.         if ($request_uri ~* "/Common/") {

  22.                 return 403;

  23.         }

  24.         if ($request_uri ~* "/Common/sh") {

  25.                 return 403;

  26.         }

  27.         location ~ .*\.(php|php5)?$ {

  28.             try_files $uri =404;

  29.             fastcgi_pass  127.0.0.1:9000;

  30.             fastcgi_index index.php;

  31.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

  32.             include fastcgi_params;

  33.         }

  34.         if ( $fastcgi_script_name ~ \..*\/.*php ) {

  35.             return 403;

  36.         }

  37.   }

“Nginx反向代理和負(fù)載均衡部署方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

網(wǎng)站名稱:Nginx反向代理和負(fù)載均衡部署方法
文章位置:http://bm7419.com/article30/gosdpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管