centos7 安装nginx配置负载均衡、反代理
1、安装c++编译环境,如已安装可略过 [html]view plain copy [root@xxx]#yuminstallgcc-c++ 2、下载组件,下载到 cd /usr/local/dowload/ [root@xxx]# wget http://nginx.org/download/nginx-1.10.2.tar.gz [root@xxx]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz [root@xxx]# wget http://zlib.net/zlib-1.2.11.tar.gz [root@xxx]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz 3、各自解压安装 openssl安装 [html]view plain copy [root@xxx]#tarzxvfopenssl-fips-2.0.10.tar.gz [root@xxx]#cdopenssl-fips-2.0.10 [root@localhostopenssl-fips-2.0.10]#./config&&make&&makeinstall zlib安装 [html]view plain copy [root@xxx]#tarzxvfzlib-1.2.11.tar.gz [root@xxx]#cdzlib-1.2.11 [root@localhostzlib-1.2.11]#./configure&&make&&makeinstall openssl安装 [html]view plain copy [root@xxx]#tarzxvfpcre-8.40.tar.gz [root@xxx]#cdpcre-8.40 [root@localhostpcre-8.40]#./configure&&make&&makeinstall nginx安装 [html]view plain copy [root@xxx]#tarzxvfnginx-1.10.2.tar.gz [root@xxx]#cdnginx-1.10.2 [root@localhostnginx-1.10.2]#./configure&&make&&makeinstall 4、Nginx启动和测试 [html]view plain copy [root@xxx]#whereisnginx [html]view plain copy cd/usr/local/nginx/ 启动 [html]view plain copy sbin/nginx 上面表示已经启动过 测试 [html]view plain copy curllocalhost:81 我的修改过,把80修改了81 浏览器测试 ---------------------------------------成功安装------------------------------------------------------------ 5、负载均衡简单配置 修改配置 vim /usr/local/nginx/conf/nginx.conf 我的nginx.conf,去掉了暂时不需要的 [html]view plain copy worker_processes1; events{ worker_connections1024; } http{ includemime.types; default_typeapplication/octet-stream; sendfileon; keepalive_timeout65; upstreambbb.test.com{ ip_hash; server10.150.7.248:8080; } server{ listen8080; server_nameaaa.test.com; location/{ proxy_passhttp://bbb.test.com; } error_page500502503504/50x.html; location=/50x.html{ roothtml; } } server{ listen81; server_namenginx.test1.com; location/{ roothtml; indexindex.htmlindex.htm; } error_page500502503504/50x.html; location=/50x.html{ roothtml; } } } 配置说明 upstream xxx{};upstream 模块是命名一个后端服务器组,组名必须为后端服务器站点域名,内部可以写多台服务器ip和port, 还可以设置跳转规则及权重等等 ip_hash;代表使用ip地址方式分配跳转后端服务器,同一ip请求每次都会访问同一台后端服务器 server;代表后端服务器地址 server{};server模块依然是接收外部请求的部分 server_name;代表外网访问域名 location / {};同样代表过滤器,用于制定不同请求的不同操作 proxy_pass;代表后端服务器组名,此组名必须为后端服务器站点域名 server_name和upstream{}的组名可以不一致,server_name是外网访问接收请求的域名,upstream{}的组名是跳转后端服务器时站点访问的域名 ----------------------------------------------说明一下----------------------------------------------------------------------------------------------------------------------------- window是我启动了tomcat----8080-----------------------------10.150.7.248:8080 window 下载switchhosts----------------------------------------ip重定向-----10.150.7.157 aaa.test.com centos7的ip-----------------10.150.7.157 window下浏览器测试 aaa.test.com:8080 -------------------------成功----------------------------------------------------------- 是不是有点蒙圈