nginx安装 (centos7) 配置分发tomcat

1.背景

    需求: nginx分发6个tomcat 

2.nginx 安装

非容器安装 
1. yum安装

## 准备工作安装 openssl zlib pcre
yum -y install openssl zlib pcre
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install nginx
2. 启动
service nginx start
--Redirecting to /bin/systemctl start nginx.service
## 自启
systemctl enable nginx

 

3. selinux设置

 

     查看是否开启

  selinux sestatus -v  

    /usr/sbin/sestatus -v 

  ### 若显示SELinux status: enabled代表开启了selinux

   永久关闭

  vi /etc/selinux/config

  ## 将SELINUX=enforcing改为SELINUX=disabled

    ## 设置完成后重启服务才生效

 reboot

 

4. 优化

开启Gzip

## 在nginx.conf文件中修改或增加如下内容
gzip on;
gzip_http_version 1.1;
gzip_comp_level 3;
gzip_types text/css
application/javascript text/plain application/json application/x-javascript
application/css application/xml application/xml+rss text/javascript
application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp;
修改上传附件限制


#### 在/etc/nginx/nginx.conf文件中修改或增加如下内容
client_max_body_size 100M;
修改请求超时设置


#### 在/etc/nginx/nginx.conf文件中修改或增加如下内容
proxy_read_timeout 240s;
修改启动用户


#### 在/etc/nginx/nginx.conf文件中修改
user nginx;
## 改为
user root;
  • 查看nginx是否启动成功
    • ps -ef|grep nginx

 

5.配置tomcat分发 

    修改 nginx.conf 文件:


    include /etc/nginx/conf.d/*.conf;
    upstream serverpool{
        ip_hash;
        server 192.168.18.146:8001;
        server 192.168.18.146:8002;
        server 192.168.18.146:8010;
        server 192.168.18.147:8001;
        server 192.168.18.147:8002;
        server 192.168.18.147:8010;
    }
    server {
        listen 8899;
        server_name localhost;
        location / {
            # proxy_pass http://serverpool;
            proxy_pass http://serverpool/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout    6500s;
            proxy_read_timeout       6500s;
            proxy_send_timeout       6500s;
        }
    }
}

6.tips

# nginx 日志路径:
/var/log/nginx

# 重启nginx:
/bin/systemctl restart nginx.service
# 查看nginx的状态
systemctl status nginx.service

netstat -anp|grep nginx

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值