1、安装Nginx
1.1、添加Nginx源
cd /etc/yum.repos.d/
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.2、安装Nginx
安装依赖
yum install -y gcc pcre-devel openssl-devel zlib-devel
安装Nginx
yum install -y nginx
2、配置代理
修改监听端口、代理规则
vim /etc/nginx/conf.d/default.conf
# $uri表示url路径,$request_uri表示url路径+参数
upstream teststream {
hash $uri;
server ip1:port1 max_fails=50 fail_timeout=600s;
server ip2:port2 max_fails=50 fail_timeout=600s;
}
server {
listen 10088;
location / {
proxy_pass http://teststream ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 60;
}
}
3、启动服务
启动服务:
systemctl start nginx.service
关闭服务:
systemctl stop nginx.service
重启服务:
systemctl restart nginx.service
查看服务:
ps aux|grep nginx