Centos7怎么实现nginx反向代理
Centos7怎么实现nginx反向代理
本篇内容主要讲解“Centos7怎么实现nginx反向代理”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Centos7怎么实现nginx反向代理”吧!
反向代理服务器架设在服务器端,通过缓冲经常被请求的页面来缓解服务器的工作量,将客户机请求转发给内部网络上的目标服务器;并将从服务器上得到的结果返回给Internet上请求连接的客户端,此时代理服务器与目标主机一起对外表现为一个服务器。目前web网站使用反向代理,除了可以防止外网对内网服务器的恶性攻击、缓存以减少服务器的压力和访问安全控制之外。
实验环境:
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-yinstallopensslopenssl-develpcrepcre-develgcc
安装nginx软件包命令集合
[root@localhost~]#mkdir/app[root@localhost~]#cd/app[root@localhost~]#wget-qhttp://nginx.org/download/nginx-1.6.3.tar.gz[root@localhost~]#useradd-s/sbin/nologin-M[root@localhost~]#tarxfnginx-1.6.3.tar.gz[root@localhost~]#cdnginx-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&&makeinstall
配置文件
(以下操作在web01和web02上进行)
[root@localhost~]#vim/app/nginx/conf/nginx.conf
将配置文件修改为以下内容
worker_processes1;events{worker_connections1024;}http{includemime.types;default_typeapplication/octet-stream;sendfileon;keepalive_timeout65;log_formatmain'$remote_addr-$remote_user[$time_local]"$request"''$status$body_bytes_sent"http_referer"''"$http_user_agent""$http_x_forwarded_for"';server{listen80;server_namebbs.dengchuanghai.org;location/{roothtml/bbs;indexindex.htmlindex.htm;}access_loglogs/access_bbs.logmain;}}[root@localhost~]#mkdir/app/nginx/html/bbs[root@localhost~]#echo"192.168.1.189bbs">>/app/nginx/html/bbs/index.html[root@localhost~]#echo"192.168.1.189bbs.dengchuanghai.org">>/etc/hosts[root@localhost~]#echo"192.168.1.190bbs">>/app/nginx/html/bbs/index.html[root@localhost~]#echo"192.168.1.190bbs.dengchuanghai.org">>/etc/hosts
(分别在两台web服务器上输入以上内容)
然后分别启动nginx
[root@localhost~]#/app/nginx/sbin/nginx-t(检查配置文件有无错误)[root@localhost~]#/app/nginx/sbin/nginx启动[root@localhost~]#ss-tnlp|grep80
使用curl bbs.dengch ,以下操作在nginx负载均衡器上进行
[root@localhost~]#vim/app/nginx/conf/nginx.conf
更改为如下内容
worker_processes1;events{worker_connections1024;}http{includemime.types;default_typeapplication/octet-stream;sendfileon;keepalive_timeout65;upstreamwww_server_pools{server192.168.1.190:80weight=1;server192.168.1.189:80weight=1;}server{listen80;server_namewww.dengchuanghai.org;location/{proxy_passhttp://www_server_pools;}}}[root@localhost~]#echo"192.168.1.188www.dengchuanghai,org">>/etc/hosts
检查语法
[root@localhost~]#/app/nginx/sbin/nginx-t
启动服务
[root@localhost~]#/app/nginx/sbin/nginx
使用curl www.dengchuanghai.org 发现结果输出为两台服务器轮流输出
到此,相信大家对“Centos7怎么实现nginx反向代理”有了更深的了解,不妨来实际操作一番吧!这里是恰卡编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
推荐阅读
-
Linux中如何配置和使用 Nginx 服务器
-
Linux如何安装和配置 Nginx 服务器
-
windows7安装centos
近期有些网友想要了解windows?7安装centos的相关情况,小编通过整理给您分享一下。为什么要在Windows7上安装Ce...
-
centos(7安装教程 centos7.9安装没有图形界面)
centos7.9安装没有图形界面?centos7.9部分安装的之后的删除镜像所以会选择带tools环境的,不要直接下载优化目标的...
-
centos(7如何关掉桌面休眠 为什么安卓系统这么好用,为何不出电脑系统)
为什么安卓系统这么好用,为何不出电脑系统?安全系统可以不能和华为相比。;鸿蒙系统系统。华为鸿蒙系统系统比安卓0倍,节省10倍,...
-
linux Centos如何安装PHP7
linuxCentos如何安装PHP7今天小编给大家分享一下li...
-
从7到8,CentOS又更新了什么
-
Centos7安装和搭建Apache+PHP+Mysql环境和常见问题处理(一)
-
如何在CentOS 8上安装PHP 7.4
-
CentOS8 安装数据库管理工具之phpMyAdmin5.1.1