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

清疚 2022-04-12 05:45 588阅读 0赞

环境为腾讯云的CentOS 7.5 64位

①安装nginx

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

②修改配置文件

进入默认配置文件的目录

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

vim编辑nginx.conf

  1. [root@VM_0_14_centos nginx]# vim nginx.conf

修改server部分

  1. server {
  2. listen 80 default_server;
  3. listen [::]:80 default_server;
  4. server_name _;
  5. root /usr/share/nginx/html;
  6. # Load configuration files for the default server block.
  7. include /etc/nginx/default.d/*.conf;
  8. location / {
  9. proxy_pass http://服务器IP:8080/;
  10. }
  11. error_page 404 /404.html;
  12. location = /40x.html {
  13. }
  14. error_page 500 502 503 504 /50x.html;
  15. location = /50x.html {
  16. }
  17. }

wq保存退出

nginx -t 测试配置文件

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

启动nginx

  1. [root@VM_0_14_centos nginx]# nginx

之前启动过了,重启nginx

  1. [root@VM_0_14_centos nginx]# nginx -s reload

设置开机自启动nginx

  1. [root@VM_0_14_centos nginx]# chkconfig nginx on

小记,完

发表评论

表情:
评论列表 (有 0 条评论,588人围观)

还没有评论,来说两句吧...

相关阅读