一 环境安装
1、需要安装gcc的环境。yum install gcc-c++ 2、第三方的开发包。 nPCRE PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。 yum install -y pcre pcre-devel 注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。 nzlib zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。 yum install -y zlib zlib-devel nopenssl OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。 nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。 yum install -y openssl openssl-devel
二、安装nginx
下载nginx wget http://nginx.org/download/nginx-1.12.2.tar.gz
解压 tar -xzvf nginx-1.12.2.tar.gz
-bash: --lock-path=ar/lockinx.lock: 没有那个文件或目录
cd nginx-1.12.2.tar.gz
编译安装
./configure
make
make install
安装完后 需要开启防护墙端口 不然访问不了
1)连接上Linux后执行 cd /etc/sysconfig命令
2)执行vim iptables命令,编辑信息,在ssh的默认端口是22,把你所需要开放的端口添加到该文件中,如80、81端口,就是我需要的。
3)配置完成后,重启防火墙设置 service iptables restart (关键步骤必须重启)
4)进入/usr/local/nginx 路径 找到sbin文件下的nginx 启动nginx
./nginx -c /usr/local/nginx/conf/nginx.conf
三 nginx 反向代理和复制均衡
upstream tomcataa{ ip_hash; server 192.168.1.114:8080; server 192.168.1.114:8082 weight=2 ; }
server { listen 80; server_name www.aa.com; #charset koi8-r; #access_log logs/host.access.log main;
location / {
#把root 修改成 proxy_pass 并在upstream 配置参数 注意http://tomcataa和 upstream 必须一致
weight=2是修改权重的意思 权重越大 越容易被访问,默认权重为一 ip_hash是为了保存session会话。
proxy_pass http://tomcataa; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
