成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

掌握Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟

創(chuàng)新互聯(lián)專注于元寶山企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),成都做商城網(wǎng)站。元寶山網(wǎng)站建設(shè)公司,為元寶山等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站制作,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)

下文給大家?guī)碚莆誑ginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟,希望能夠給大家在實際運用中帶來一定的幫助,負載均衡涉及的東西比較多,理論也不多,網(wǎng)上有很多書籍,今天我們就用創(chuàng)新互聯(lián)在行業(yè)內(nèi)累計的經(jīng)驗來做一個解答。

Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)

 

什么是反向代理與負載均衡

Nginx僅僅作為Nginx  proxy反向代理使用的,因為這個反向代理功能表現(xiàn)的效果是負載均衡集群的效果。

負載均衡指的是對請求數(shù)據(jù)包的轉(zhuǎn)發(fā),從負載均衡下面的節(jié)點云服務(wù)器來看,接收到的請求還是來自訪問負載均衡器的客戶端的真實用戶,而反向代理服務(wù)器指的是接收到用戶的請求后,會代理用戶重新發(fā)起請求代理下的節(jié)點服務(wù)器,最后把數(shù)據(jù)返回給客戶端用戶,在節(jié)點服務(wù)器看來,范文的節(jié)點服務(wù)器的客戶端用的就是反向代理服務(wù)器了,而非真實的網(wǎng)站訪問用戶。

Nginx負載均衡核心組件介紹

Nginx http功能模塊

模塊說明

ngx_nginx upstream

負載均和模塊,可以實現(xiàn)網(wǎng)站的負載均衡功能及節(jié)點的健康檢查

ngx_http_proxy_module

Proxy模塊,用于把請求后拋給服務(wù)器節(jié)點或upstream服務(wù)器池

一、實驗?zāi)繕?/strong>

實戰(zhàn)1:配置基于域名虛擬主機的web節(jié)點

實戰(zhàn)2:實現(xiàn)代理服務(wù)器攜帶主機頭和記錄用戶IP

實戰(zhàn)3:根據(jù)URL中的目錄地址實現(xiàn)代理轉(zhuǎn)發(fā)

實戰(zhàn)4:Nginx負載均衡檢測節(jié)點狀態(tài)

 

二、實驗環(huán)境

主機名

IP地址

系統(tǒng)

作用

yu61

192.168.1.61

Rhel-6.5

nginx的主負載均衡器

yu62

192.168.1.62

Rhel-6.5

nginx的從負載均衡器

yu63

192.168.1.63

Rhel-6.5

Web1服務(wù)器

yu64

192.168.1.64

Rhel-6.5

Web2服務(wù)器

實驗拓撲

掌握Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟 

三、實驗步驟

1、Nginx的安裝------四臺主機都是怎么安裝

[root@yu61 ~]#service httpd stop

[root@yu61 ~]#service iptables stop

[root@yu61 ~]#yum install pcre pcre-devel openssl openssl-devel -y

[root@yu61 ~]# mkdir -p /home/yu/tools

[root@yu61 ~]# cd /home/yu/tools/

[root@yu61 tools]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

[root@yu61 tools]# ls

nginx-1.6.3.tar.gz

[root@yu61 tools]# useradd nginx -s /sbin/nologin -M

[root@yu61 tools]# tar xf nginx-1.6.3.tar.gz

[root@yu61 tools]# cd nginx-1.6.3

[root@yu61 nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3 --with-http_stub_status_module --with-http_ssl_module

[root@yu61 nginx-1.6.3]#make -j 4 && make install

[root@yu61 nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx

 

 

Nginx負載均衡實戰(zhàn)

實戰(zhàn)1:配置基于域名虛擬主機的web節(jié)點

1、修改配置文件------在兩臺web服務(wù)器上修改

[root@yu61 nginx-1.6.3]# cd /application/nginx/conf/

[root@yu61 conf]# egrep -v '#|^$' nginx.conf.default > nginx.conf

[root@yu63 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    server {

        listen       80;

        server_name  bbs.mobanche.com;

        location / {

            root   html/bbs;

            index  index.html index.htm;

        }

access_log  logs/access.log  main;

        }

    }

    server {

        listen       80;

        server_name  www.mobanche.com;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

access_log  logs/access.log  main;

        }

    }

}

 

2、檢查語法和啟動nginx服務(wù)----------四臺主機都做

[root@yu61 conf]# mkdir /application/nginx/html/{www,bbs}

[root@yu61 conf]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@yu61 conf]# /application/nginx/sbin/nginx

[root@yu61 conf]# netstat -anutp | grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      48817/nginx

 

3、添加可測試內(nèi)容-------兩臺web主機都做,測試用可以只做一臺

[root@yu63 conf]# echo '192.168.1.63 www' > ../html/www/index.html

[root@yu63 conf]# echo '192.168.1.63 bbs' > ../html/bbs/index.html

[root@yu63 conf]# cat /application/nginx/html/www/index.html

192.168.1.63 www

[root@yu63 conf]# cat /application/nginx/html/bbs/index.html

192.168.1.63 bbs

[root@yu64 conf]# echo '192.168.1.64 www' > ../html/www/index.html

[root@yu64 conf]# echo '192.168.1.64 bbs' > ../html/bbs/index.html

[root@yu64 conf]# cat /application/nginx/html/www/index.html

192.168.1.64 www

[root@yu64 conf]# cat /application/nginx/html/bbs/index.html

192.168.1.64 bbs

 

4、用curl測試web端

[root@yu61 conf]# tail -2 /etc/hosts

192.168.1.63 bbs

192.168.1.63 www

[root@yu61 conf]# scp  /etc/hosts  /etc/hosts 192.168.1.63:/etc/hosts

[root@yu61 conf]# curl www.mobanche.com

192.168.1.63 www

[root@yu61 conf]# curl bbs.mobanche.com

192.168.1.63 bbs

 

實戰(zhàn)2:實現(xiàn)代理服務(wù)器攜帶主機頭和記錄用戶IP

1)Upstream模塊的介紹

Nginx的負載均衡功能依賴于ngx_http_proxy_module模塊,所支持代理方式包括proxy_pass(代理)、fastcgi_pass(PHP/JAVA)、memcache_pass(緩存)等。

ngx_http_proxy_module模塊允許Nginx定義一組或度組節(jié)點服務(wù)器組,使用時可以通過pass_pass代理方式吧網(wǎng)站的請求發(fā)送到實現(xiàn)定義好ID對應(yīng)upstream組的名字上。

負載均衡模塊用于從”upstream”指令定義的后端主機列表中選取一臺主機。Nginx先使用負載均衡模塊找到一臺主機,再使用upstream模塊實現(xiàn)與這臺主機的交互。

2)Upstream模塊語法:

upstream www_server_pools #upstream是關(guān)鍵字必須要有,www_server_pools是upstream集群組的名字,可以自定義。

server 192.168.1.63:80 weight=1; #server是關(guān)鍵字,這是固定的,后面可以接域名或者ip地址,如果布置點端口,默認是80端口,weight是權(quán)重,數(shù)值越大被分配的請求越多,結(jié)尾是分號。

3)Upstream模塊相關(guān)說明

Upstream模塊的內(nèi)容應(yīng)放于http{}標簽中,其默認調(diào)度算法是wrr,權(quán)重輪詢。

Upstream模塊內(nèi)部server標簽參數(shù)說明

Upstream模塊內(nèi)參數(shù)

參數(shù)說明

server 192.168.1.63

負載均衡后面的節(jié)點服務(wù)器配置,可以是ip或域名,如果端口號不寫,默認端口是80,高并發(fā)情況下,ip可以換成域名,通過DNS做負載均衡。

weight=1

代表權(quán)重,默認值是1,權(quán)重數(shù)值越大表示接受的請求比例越大

max_fails=1

Nginx嘗試連接后端主機失敗的次數(shù)。這個數(shù)值是配合proxy_pass(代理)、fastcgi_pass(PHP/JAVA)、memcache_pass(緩存)三個參數(shù)使用的。當Nginx接受到后端服務(wù)器返回這三個參數(shù)定義的狀態(tài)碼時,會將這個請求轉(zhuǎn)發(fā)給正常工作的后端服務(wù)器。

backup

熱備,real server節(jié)點的高可用,當前面激活的RS都失敗后會自動啟用熱備RS,這標志著買這個服務(wù)器作為備份服務(wù)器,若主服務(wù)區(qū)全部宕機了,就會轉(zhuǎn)發(fā)他的請求,

fail_timeout=10s

在max_fails定義的失敗次數(shù)后,距離下次檢查的時間間隔,默認是10秒。如果max_fails=5,他就檢測5次,如果5此都是502,它就會根據(jù)fail_timeout的值,等待10秒后再去檢查。只檢查一次,如果持續(xù)502。在不重新加載Nginx配置的情況下,每隔10秒值檢查一次。

down

這標志著服務(wù)器永遠不可用,這個參數(shù)可以配合ip_hash使用。

4)upstream模塊3種常用的調(diào)度算法方式
        Nginx的upstream支持5種分配方式。其中,前三種為Nginx原生支持的分配方式,后兩種為第三方支持的分配方式:
(1)、rr輪詢    
        輪詢是upstream的默認分配方式,即每個請求按照時間順序輪流分配到不同的后端服務(wù)器,如果某個后端服務(wù)器down掉后,能自動剔除。按照1:1輪詢。
        upstream backend {
            server 192.168.1.101:88;
            server 192.168.1.102:88;
        }
(2)、wrr輪詢。      
        輪詢的加強版,即可以指定輪詢比率,weight和訪問幾率成正比,主要應(yīng)用于后端服務(wù)器異質(zhì)的場景下。
        upstream backend {
            server 192.168.1.101 weight=1;
            server 192.168.1.102 weight=2;
            server 192.168.1.103 weight=3;
        }
(3)、ip_hash        
        每個請求按照訪問ip(即Nginx的前置服務(wù)器或者客戶端IP)的hash結(jié)果分配,這樣每個訪客會固定訪問一個后端服務(wù)器,可以解決session一致問題。
        upstream backend {
            ip_hash;
            server 192.168.1.101:81;
            server 192.168.1.102:82;
            server 192.168.1.103:83;
        }

(4)、fair        
        fair顧名思義,公平地按照后端服務(wù)器的響應(yīng)時間(rt)來分配請求,響應(yīng)時間短即rt小的后端服務(wù)器優(yōu)先分配請求。
        upstream backend {
            server 192.168.1.101;
            server 192.168.1.102;
            fair;
        }
(5)、url_hash
        與ip_hash類似,但是按照訪問url的hash結(jié)果來分配請求,使得每個url定向到同一個后端服務(wù)器,主要應(yīng)用于后端服務(wù)器為緩存時的場景下。
        upstream backend {
            server 192.168.1.101;
            server 192.168.1.102;
            hash $request_uri;
            hash_method crc32;
        }
注意:

_method為使用的hash算法,需要注意的是:server語句中不能加weight等參數(shù)。后邊兩種目前作了解即可。

 

5)http proxy模塊參數(shù)

http proxy模塊參數(shù)

參數(shù)說明

proxy_set_header

允許重新定義或附加字段到傳遞到代理服務(wù)器的請求標頭。 該值可以包含文本,變量及其組合??蓪崿F(xiàn)讓代理后端的服務(wù)器的節(jié)點獲取到客戶端用戶的證書IP地址。

proxy_connect_timeout

指定一個連接到代理服務(wù)器的超時時間,單位為秒,需要注意的是這個時間最好不要超過75秒。

proxy_body_buffer_size

用于指定客戶端請求緩沖區(qū)大小

proxy_send_timeout

表示代理后端服務(wù)器的數(shù)據(jù)回傳時間,即在規(guī)定時間之內(nèi)后端服務(wù)器必須傳完所有的數(shù)據(jù),否則,Nginx將斷開這個鏈接

proxy_read_timeout

設(shè)置Nginx從代理的后端服務(wù)器獲取信息的時間,表示鏈接建立成功后,Nginx等待后端服務(wù)器的響應(yīng)時間,其實是Nginx以及進入后端的排隊之中等候處理時間

Proxy_buffer_size

設(shè)置緩沖區(qū)的數(shù)量和大小,Nginx從代理的后端服務(wù)器獲取的響應(yīng)信息,會防止到緩沖區(qū)

Proxy_buffers

用于設(shè)置設(shè)置緩沖區(qū)的數(shù)量和大小,Nginx從代理的后端服務(wù)器獲取響應(yīng)信息,會防止到緩沖區(qū)

Proxy_busy_buffer_size

用于設(shè)置系統(tǒng)很忙時可以使用的peoxy_buffers大小,

Proxy_temp_file_write_size

指定peoxy緩存臨時文件的大小

 

1、修改nginx主從服務(wù)器------兩臺負載均衡器主機都要修改

[root@yu61 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    upstream www_server_pools{

server 192.168.1.63:80 weight=1;

server 192.168.1.64:80 weight=1;

}

    server {

        listen       80;

        server_name  www.mobanche.com;

        location / {

proxy_pass http://www_server_pools;

        }

    }

}

2、測試負載均衡

[root@yu61 conf]# ../sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@yu61 conf]# ../sbin/nginx -s reload

[root@yu61 conf]# cat /etc/hosts

192.168.1.61 www.mobanche.com

[root@yu61 conf]# curl www.mobanche.com

192.168.1.63 bbs

[root@yu61 conf]# curl www.mobanche.com

192.168.1.64 bbs

[root@yu61 conf]# curl www.mobanche.com

192.168.1.63 bbs

[root@yu61 conf]# curl www.mobanche.com

192.168.1.64 bbs

注釋:

默認沒有在請求頭來告訴節(jié)點服務(wù)器找那臺虛擬機主機,所以,web節(jié)點服務(wù)器接收到請求后發(fā)現(xiàn)沒有主機頭信息,因此,就把節(jié)點服務(wù)器的第一個虛擬機主機發(fā)給看反向代理了(二節(jié)點上的第一個虛擬主機放置的第一個是bbs),解決這個問題的辦法,就是當反向代理想后重新發(fā)起請求時,要攜帶主機頭信息,以明確的告訴節(jié)點服務(wù)器要找哪一個虛擬主機。

3、修改配置文件-添加代理服務(wù)器攜帶主機頭文件配置

[root@yu61 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    upstream www_server_pools{

server 192.168.1.63:80 weight=1;

server 192.168.1.64:80 weight=1;

}

    server {

        listen       80;

        server_name  www.mobanche.com;

        location / {

proxy_pass http://www_server_pools;

proxy_set_header Host $host;

        }

    }

}

4、使用另外一個客戶端測試

[root@yu61 conf]# curl www.mobanche.com

192.168.1.63 www

[root@yu61 conf]# curl www.mobanche.com

192.168.1.64 www

[root@yu62 ~]# curl www.mobanche.com

192.168.1.64 www

[root@yu62 ~]# curl www.mobanche.com

192.168.1.63 www

[root@yu61 conf]# tail -2 /application/nginx/logs/access.log

192.168.1.61 - - [18/May/2017:19:44:04 +0800] "GET / HTTP/1.1" 200 17 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh4/1.4.2" "-"

192.168.1.61 - - [18/May/2017:19:44:05 +0800] "GET / HTTP/1.1" 200 17 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh4/1.4.2" "-"

5、再次修改配置文件,添加代理服務(wù)器獲取用戶IP配置

[root@yu61 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    upstream www_server_pools{

server 192.168.1.63:80 weight=1;

server 192.168.1.64:80 weight=1;

}

    server {

        listen       80;

        server_name  www.mobanche.com;

        location / {

proxy_pass http://www_server_pools;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

        }

    }

}

 

用于查看的客戶端需要開啟log記錄

掌握Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟 

 

6、測試

[root@yu64 conf]# tail -2 /application/nginx/logs/access.log

192.168.1.61 - - [18/May/2017:19:56:19 +0800] "GET / HTTP/1.0" 200 17 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh4/1.4.2""192.168.1.62"

192.168.1.61 - - [18/May/2017:19:56:19 +0800] "GET / HTTP/1.0" 200 17 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh4/1.4.2""192.168.1.62"

 

實戰(zhàn)3:根據(jù)URL中的目錄地址實現(xiàn)代理轉(zhuǎn)發(fā)

實驗拓撲

掌握Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟 

 

(1)當用戶訪問www.mobanche.com/upload/xxx的時候,代理服務(wù)器會吧請求分配到上傳服務(wù)器池處理數(shù)據(jù)。

(2)當用戶訪問www.mobanche.com/static/xxx的時候,代理服務(wù)器會吧請求分配到動態(tài)上傳服務(wù)器池請求數(shù)據(jù)。

(3)當用戶訪問www.mobanche.com//xxx的時候,不包含任何指定的目錄地址路徑時。代理服務(wù)器會把請求分配到默認的動態(tài)服務(wù)器池請求數(shù)據(jù)

1、修改配置文件,添加地址池

[root@yu61 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    upstream upload_pools{

server 192.168.1.63:80 weight=1;

}

    upstream static_pools{

server 192.168.1.64:80 weight=1;

}

    upstream default_pools{

server 192.168.1.62:80 weight=1;

}

    server {

        listen       80;

        server_name  www.mobanche.com;

        location / {

proxy_pass http://default_pools;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

        }

location /static/ {

proxy_pass http://static_pools;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

        }

        location /upload/ {

proxy_pass http://upload_pools;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

        }

    }

}

2、重啟Nginx

[root@yu61 conf]# ../sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@yu61 conf]# ../sbin/nginx -s reload

3、測試靜態(tài)分離

[root@yu64 www]# cat /etc/hosts

192.168.1.64 bbs.mobanche.com

192.168.1.64 www.mobanche.com

[root@yu64 nginx]# cd html/www/

[root@yu64 www]# mkdir static

[root@yu64 www]# echo static_pools > static/index.html

[root@yu64 www]# curl http://www.mobanche.com/static/index.html

static_pools

 

[root@yu63 www]# cat /etc/hosts

192.168.1.63 bbs.mobanche.com

192.168.1.63 www.mobanche.com

[root@yu63 nginx]#  cd html/www/

[root@yu63 www]# mkdir upload

[root@yu63 www]# echo upload_pools > upload/index.html

[root@yu63 www]# curl http://www.mobanche.com/upload/index.html

upload_pools

 

[root@yu65 www]# cat /etc/hosts

192.168.1.65 bbs.mobanche.com

192.168.1.65 www.mobanche.com

[root@yu65 nginx]#  cd html/www/

[root@yu65 www]# echo default_pools > index.html

[root@yu65 www]# curl http://www.mobanche.com

default_pools

 

實戰(zhàn)4:Nginx負載均衡檢測節(jié)點狀態(tài)

1、安裝軟件

[root@yu61 tools]# pwd

/home/yu/tools

[root@yu61 tools]# wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master

[root@yu61 tools]# unzip master

[root@yu61 tools]# cd nginx-1.6.3

[root@yu61 nginx-1.6.3]# patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch

[root@yu61 nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3 --with-http_stub_status_module --with-http_ssl_module --add-module=../nginx_upstream_check_module-master

--add-module=../nginx_upstream_check_module-master

[root@yu61 nginx-1.6.3]# make

[root@yu61 nginx-1.6.3]# mv /application/nginx/sbin/nginx{,.ori}

[root@yu61 nginx-1.6.3]# cp ./objs/nginx /application/nginx/sbin/

2、檢測配置文件

[root@yu61 nginx-1.6.3]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@yu61 nginx-1.6.3]# /application/nginx/sbin/nginx -V

nginx version: nginx/1.6.3

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)

TLS SNI support enabled

configure arguments: --user=nginx --group=nginx --prefix=/application/nginx-1.6.3 --with-http_stub_status_module --with-http_ssl_module --add-module=../nginx_upstream_check_module-master

check interval=3000 rise=2 fall=5 timeout=1000 type=http;

3、修改配置文件

[root@yu61 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    upstream static_pools{

server 192.168.1.64:80 weight=1;

server 192.168.1.63:80 weight=1;

check interval=3000 rise=2 fall=5 timeout=1000 type=http;

}

    upstream default_pools{

        server 192.168.1.62:80 weight=1;

        }

    server {

        listen       80;

        server_name  www.mobanche.com;

        location / {

root html;

    index  index.html index.htm

proxy_pass http://default_pools;

proxy_set_header Host $host;

proxy_set_header X-Forwarded-For $remote_addr;

        }

        location /status {

check_status;

access_log off;

        }

    }

}

4、重啟服務(wù)測試

[root@yu61 conf]# ../sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@yu61 conf]# ../sbin/nginx -s stop

[root@yu61 conf]# ../sbin/nginx

掌握Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟

看了以上關(guān)于掌握Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟,如果大家還有什么地方需要了解的可以在創(chuàng)新互聯(lián)行業(yè)資訊里查找自己感興趣的或者找我們的專業(yè)技術(shù)工程師解答的,創(chuàng)新互聯(lián)技術(shù)工程師在行業(yè)內(nèi)擁有十幾年的經(jīng)驗了。

 

 

新聞名稱:掌握Nginx之反向代理與負載均衡實現(xiàn)動靜分離實戰(zhàn)的方法及步驟
轉(zhuǎn)載源于:http://jinyejixie.com/article22/ppjcjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷面包屑導(dǎo)航、域名注冊網(wǎng)站維護、動態(tài)網(wǎng)站、做網(wǎng)站

廣告

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