欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Nginx負(fù)載均衡/SSL配置的實(shí)現(xiàn)

今天就跟大家聊聊有關(guān)Nginx負(fù)載均衡/SSL配置的實(shí)現(xiàn),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比岑溪網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式岑溪網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋岑溪地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴(lài)。

什么是負(fù)載均衡?

當(dāng)一個(gè)域名指向多臺(tái)web服務(wù)器時(shí),添加一臺(tái)nginx負(fù)載均衡服務(wù)器,通過(guò)nginx負(fù)載均衡即可將來(lái)自于客戶(hù)端的請(qǐng)求均衡的發(fā)送給每臺(tái)web服務(wù)器,避免單臺(tái)服務(wù)器負(fù)載過(guò)高而其余服務(wù)器較為空閑的不均衡情況出現(xiàn)

配置nginx負(fù)載均衡:

在nginx機(jī)器上新建配置文件:

[root@centos02 ~]# vi /etc/nginx/conf.d/test.conf

添加如下內(nèi)容:

upstream test
 {
  ip_hash; 
  server 192.168.0.10:80 weight=100; 
  server 192.168.0.20:80 weight=50;
 }
 server
 {
  listen 80;
  server_name www.test.com;
  location /
  {
   proxy_pass http://test;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
 }
  • upstream:負(fù)載均衡配置

  • test:自定義名,用于server{}中proxy_pass引用

  • ip_hash:將同一客戶(hù)端的所有請(qǐng)求發(fā)送給同一服務(wù)器(如不發(fā)送給同一服務(wù)器,有可能出現(xiàn)客戶(hù)端剛登陸網(wǎng)站,點(diǎn)擊其他子頁(yè)面又提示登陸)

  • server:web服務(wù)器地址

  • weight:定義權(quán)重(范圍0-100),負(fù)載均衡服務(wù)器優(yōu)先將請(qǐng)求發(fā)送給權(quán)重大的web服務(wù)器(以上示例如果有150條請(qǐng)求進(jìn)來(lái),192.168.0.10會(huì)被分配100條,192.168.0.20會(huì)被分配50條)

  • server_name:訪問(wèn)網(wǎng)站的域名

  • proxy_pass:引用upstream定義的名稱(chēng)

驗(yàn)證nginx配置并重載:

[root@centos02 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@centos02 ~]# nginx -s reload

接下來(lái)修改客戶(hù)端hosts文件將測(cè)試的域名www.test.com指向到測(cè)試的nginx負(fù)載均衡機(jī)器的IP即可訪問(wèn)www.test.com網(wǎng)站。

負(fù)載均衡配置示例補(bǔ)充

1.根據(jù)請(qǐng)求的文件配置:

upstream aa {   
    server 192.168.0.10;
    server 192.168.0.20; 
  }
upstream bb { 
    server 192.168.0.100;
    server 192.168.0.101;
 }
 server {
  listen  80;
  server_name www.test.com;
  location ~ aa.php
  {
   proxy_pass http://aa/;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP  $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
  location ~ bb.php
  {
    proxy_pass http://bb/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
  location /
  {
    proxy_pass http://bb/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

請(qǐng)求aa.php的,會(huì)到aa組,請(qǐng)求bb.php的會(huì)到bb組,其他請(qǐng)求全部到bb組,必須要有l(wèi)ocation / {} ,否則不能正確匹配url

2.根據(jù)請(qǐng)求的目錄配置:

upstream aa {   
    server 192.168.0.10;
    server 192.168.0.20; 
  }
upstream bb { 
    server 192.168.0.100;
    server 192.168.0.101;
 }
 server {
  listen  80;
  server_name www.test.com;
  location /dir1/
  {
   proxy_pass http://aa/dir1/;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP  $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
  location /dir2/
  {
    proxy_pass http://bb/dir2/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
  location /
  {
    proxy_pass http://bb/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

#當(dāng)請(qǐng)求uri中匹配/dir1/,代理到aa/dir1/,匹配/dir2/或者其他時(shí),代理到bb/dir2/

nginx配置SSL證書(shū)實(shí)現(xiàn)通過(guò)https協(xié)議訪問(wèn)網(wǎng)站:

SSL證書(shū)申請(qǐng)網(wǎng)站:

1.https://www.wosign.com/
2.https://freessl.cn/(免費(fèi))

#通過(guò)瀏覽器生成后,需要在服務(wù)器創(chuàng)建證書(shū)文件

創(chuàng)建證書(shū)文件:

[root@linux ~]# mkdir /etc/nginx/ssl
[root@linux ~]# cd !$
cd /etc/nginx/ssl
[root@linux ssl]# touch ca
[root@linux ssl]# touch test.crt
[root@linux ssl]# touch test.key

#將證書(shū)申請(qǐng)網(wǎng)站提供的對(duì)應(yīng)證書(shū)的內(nèi)容添加到ca/ .crt/ .key文件中即可

編輯nginx配置文件:

[root@linux ~]# vi /etc/nginx/conf.d/bbs.conf

添加如下內(nèi)容:

listen    443 ssl;
server_name test.bbs.com;
ssl on;
ssl_certificate /etc/nginx/ssl/test.crt;   #定義.crt文件路徑
ssl_certificate_key /etc/nginx/ssl/test.key;  #定義.key文件路徑
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

驗(yàn)證配置并重載nginx:

[root@linux ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@linux ~]# nginx -s reload

#接下來(lái)訪問(wèn)網(wǎng)站地址欄即可顯示HTTPS

curl驗(yàn)證方式:

curl -k -H "host:test.bbs.com" https://192.168.234.128/index.php

#host:域名,https:// webserver IP,輸出結(jié)果為網(wǎng)站頁(yè)面標(biāo)簽信息即表示成功

看完上述內(nèi)容,你們對(duì)Nginx負(fù)載均衡/SSL配置的實(shí)現(xiàn)有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

新聞名稱(chēng):Nginx負(fù)載均衡/SSL配置的實(shí)現(xiàn)
當(dāng)前鏈接:http://www.chinadenli.net/article8/iejjip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開(kāi)發(fā)企業(yè)建站品牌網(wǎng)站建設(shè)網(wǎng)站改版云服務(wù)器服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司