centos7下如何配置nginx反向代理負(fù)載均衡集群-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)centos7下如何配置nginx反向代理負(fù)載均衡集群,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

目前創(chuàng)新互聯(lián)已為近1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、德興網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
nginx是一個web服務(wù)器,類似apache一樣,但是比apache性能更好,更快。還可以實現(xiàn)反向代理,和負(fù)載均衡,常用于構(gòu)建web服務(wù)集群的負(fù)載均衡。今天就來記錄一下,nginx的安裝與配置,實現(xiàn)負(fù)載均衡的作用。

實驗環(huán)境:

192.168.1.188    nginx負(fù)載均衡器

192.168.1.189    web01服務(wù)器

192.168.1.190    web02服務(wù)器

軟件準(zhǔn)備:

centos7.4 x86_64

nginx-1.6.3.tar.gz

安裝nginx軟件

安裝依賴軟件包 命令集合

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

安裝nginx軟件包 命令集合

[root@localhost ~]# mkdir /app
[root@localhost ~]# cd /app
[root@localhost ~]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
[root@localhost ~]# useradd -s /sbin/nologin -M
[root@localhost ~]# tar xf nginx-1.6.3.tar.gz
[root@localhost ~]# cd nginx-1.6.3
[root@localhost ~]# ./configure --user=nginx --group=nginx --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module
[root@localhost ~]# make && make install

配置文件

(以下操作在web01和web02上進(jìn)行)

[root@localhost ~]# vim /app/nginx/conf/nginx.conf

將配置文件修改為以下內(nèi)容

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.dengchuanghai.org;
location / {
root html/bbs;
index index.html index.htm;
}
access_log logs/access_bbs.log main;
}
}
[root@localhost ~]# mkdir /app/nginx/html/bbs
[root@localhost ~]# echo "192.168.1.189 bbs" >>/app/nginx/html/bbs/index.html            
[root@localhost ~]# echo "192.168.1.189 bbs.dengchuanghai.org" >> /etc/hosts                     
[root@localhost ~]# echo "192.168.1.190 bbs" >>/app/nginx/html/bbs/index.html  
[root@localhost ~]# echo "192.168.1.190 bbs.dengchuanghai.org" >> /etc/hosts

(分別在兩臺web服務(wù)器上輸入以上內(nèi)容)

然后分別啟動nginx

[root@localhost ~]# /app/nginx/sbin/nginx -t (檢查配置文件有無錯誤)
[root@localhost ~]# /app/nginx/sbin/nginx  啟動
[root@localhost ~]# ss -tnlp | grep 80

使用curl bbs.dengch
centos7下如何配置nginx反向代理負(fù)載均衡集群
,以下操作在nginx負(fù)載均衡器上進(jìn)行

[root@localhost ~]# vim /app/nginx/conf/nginx.conf

更改為如下內(nèi)容

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.190:80 weight=1;
server 192.168.1.189:80 weight=1;
}
server {
listen 80;
server_name www.dengchuanghai.org;
location / {
proxy_pass http://www_server_pools;
}
}
}
[root@localhost ~]# echo "192.168.1.188 www.dengchuanghai,org" >> /etc/hosts

檢查語法

[root@localhost ~]# /app/nginx/sbin/nginx -t

啟動服務(wù)

[root@localhost ~]# /app/nginx/sbin/nginx

centos7下如何配置nginx反向代理負(fù)載均衡集群
使用curl www.dengchuanghai.org
centos7下如何配置nginx反向代理負(fù)載均衡集群
發(fā)現(xiàn)結(jié)果輸出為兩臺服務(wù)器輪流輸出

實驗結(jié)束

關(guān)于centos7下如何配置nginx反向代理負(fù)載均衡集群就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

新聞名稱:centos7下如何配置nginx反向代理負(fù)載均衡集群-創(chuàng)新互聯(lián)
地址分享:http://muchs.cn/article42/ddcoec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、建站公司、網(wǎng)站營銷、做網(wǎng)站定制開發(fā)、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(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)

微信小程序開發(fā)