Centos7+nginx+tomcat安装部署

目录:

1、安装nginx

2、安装tomcat

3、nginx+tomcat实现代理

4、nginx+tomcat简单负载均衡

 

1、安装nginx

直接通过yum方式安装,默认centos7的基本源中没有nginx,需要先安装扩展源:epel

#    yum -y install epel-release

#    yum -y install nginx

安装完成!nginx配置文件目录为:/etc/nginx 下

启动nginx

#    systemctl start nginx

启动成功!主机浏览器访问:http://ip  此时发现无法访问,这是因为centos防火墙的原因,需要将80端口加入到防火墙例外端口里面

添加80端口为例外

#    firewall-cmd --zone=public --add-port=80/tcp --permanent

重启防火墙

#    systemctl restart firewalld

主机浏览器再访问:http://192.168.0.101  成功进入nginx首页!

 

2、安装tomcat

在apache官网下载:apache-tomcat-7.0.78.tar.gz ,放到/opt  目录下

解压tomcat

#    tar -zxvf apache-tomcat-7.0.78.tar.gz

启动tomcat

进入到解压出来的tomcat bin目录

#    cd /opt/apache-tomcat-7.0.78/bin

执行启动命令

#    ./startup.sh

启动成功!主机浏览器访问:http://192.168.0.101:8080 此时发现无法访问,同理添加8080端口为例外

 

3、配置nginx代理

编辑nginx配置文件

#    vi /etc/nginx/nginx.conf

server {
        listen       80;
        server_name  192.168.0.101;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                proxy_pass http://192.168.0.101:8080;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

保存并退出:#    wq!

重新加载nginx使更改生效

#    nginx -s reload

主机浏览器访问:http://192.168.0.101 结果出现502错误,这是红帽和centos6.6版出现的问题,解决方案如下

#    yum -y install policycoreutils-python

#    cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx

#    semodule -i mynginx.pp

再访问:http://192.168.0.101 成功进入tomcat首页

 

4、多个tomcat实现负载均衡

upstream tomcats{
        server 192.168.0.101:8080;
        server 192.168.0.101:8081;
    }
    server {
        listen       80;
        server_name  192.168.0.101;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                proxy_pass http://tomcats;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

 

更多nginx配置请见:nginx+tomcat 负载均衡配置

转载于:https://my.oschina.net/u/3549345/blog/968465

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值