使用Nginx 反向代理,通过域名直接访问Tomcat 8080端口

环境为腾讯云的CentOS 7.5 64位

①安装nginx

[root@VM_0_14_centos ~]# yum install nginx -y

②修改配置文件

进入默认配置文件的目录

[root@VM_0_14_centos webapp]# cd /etc/nginx

vim编辑nginx.conf

[root@VM_0_14_centos nginx]# vim nginx.conf

修改server部分

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

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

        location / {
            proxy_pass http://服务器IP:8080/;
        }

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

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

wq保存退出

nginx -t 测试配置文件

[root@VM_0_14_centos nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动nginx

[root@VM_0_14_centos nginx]# nginx

之前启动过了,重启nginx

[root@VM_0_14_centos nginx]# nginx -s reload

设置开机自启动nginx

[root@VM_0_14_centos nginx]# chkconfig nginx on

 

小记,完

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值