新聞中心
反向代理服務器架設在服務器端,通過緩沖經(jīng)常被請求的頁面來緩解服務器的工作量,將客戶機請求轉(zhuǎn)發(fā)給內(nèi)部網(wǎng)絡上的目標服務器;并將從服務器上得到的結果返回給Internet上請求連接的客戶端,此時代理服務器與目標主機一起對外表現(xiàn)為一個服務器。目前web網(wǎng)站使用反向代理,除了可以防止外網(wǎng)對內(nèi)網(wǎng)服務器的惡性攻擊、緩存以減少服務器的壓力和訪問安全控制之外,下面為大家詳細講解一下Centos7實現(xiàn)nginx反向代理具體方法

成都創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷推廣、網(wǎng)站重做改版、桐城網(wǎng)站定制設計、自適應品牌網(wǎng)站建設、成都h5網(wǎng)站建設、電子商務商城網(wǎng)站建設、集團公司官網(wǎng)建設、成都外貿(mào)網(wǎng)站建設、高端網(wǎng)站制作、響應式網(wǎng)頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為桐城等各大城市提供網(wǎng)站開發(fā)制作服務。
實驗環(huán)境:
192.168.1.188 nginx負載均衡器
192.168.1.189 web01服務器
192.168.1.190 web02服務器
軟件準備:
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上進行)
[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服務器上輸入以上內(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 ,以下操作在nginx負載均衡器上進行
[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
啟動服務
[root@localhost ~]# /app/nginx/sbin/nginx
使用curl www.dengchuanghai.org 發(fā)現(xiàn)結果輸出為兩臺服務器輪流輸出
分享題目:Centos7實現(xiàn)nginx反向代理
鏈接URL:http://fisionsoft.com.cn/article/djhdpei.html


咨詢
建站咨詢
