66-Linux-Tomcat-nginx反向代理


请务必查看上期博客基础环境设置

基础环境及软件包安装参照上期博客内容

参照内容截止至“#访问Tomcat自定义页面

#默认已完成上述博客内容中的基础环境


实验内容

nginx反向代理

#追加一条新行
[root@C7-4 ~]# vim /etc/hosts
127.0.0.1 www.dushan.com 

#更改原先页面文件内容
[root@C7-4 ~]# echo '<h1>tomcat ROOT static index.html page from nginx !</h1>' > /usr/local/tomcat/webapps/ROOT/index.html

[root@C7-4: ~]# vim /usr/local/tomcat/webapps/ROOT/myindex.jsp 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
            <title>myapp of dushan</title>
</head>
<body>
<h1> test jsp in default ROOT dir ! </h1>
<%
out.println("hello jsp");
%>
</body>
</html> 

#设置目录属主属组
[root@C7-4 ~]# chown -R java:java /usr/local/tomcat

#安装nginx
[root@C7-4: ~]# yum -y install nginx

#查看当前安装后的nginx版本
[root@C7-4: ~]# rpm -qa nginx
nginx-1.16.1-1.el7.x86_64

#查阅nginx相关文件
[root@C7-4: ~]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
……….
/var/lib/nginx
/var/lib/nginx/tmp
/var/log/nginx
#找到如下位置,添加该行:proxy_pass http://www.dushan.com:8080;   
[root@C7-4: ~]# vim /etc/nginx/nginx.conf

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

        location / {
    
                proxy_pass http://www.dushan.com:8080;                                                                       
        }   


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


#重启nginx和tomcat服务
[root@C7-4: ~]# systemctl start nginx

[root@C7-4: ~]# su - java -c '/usr/local/tomcat/bin/startup.sh'
su: warning: cannot change directory to /home/java: No such file or directory
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/default
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.


#查看端口
[root@C7-4 ~]# ss -ntl
State       Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
LISTEN      0      100         127.0.0.1:25                              *:*                  
LISTEN      0      128                 *:80                              *:*                  
LISTEN      0      128                 *:22                              *:*                  
LISTEN      0      100             [::1]:25                           [::]:*                  
LISTEN      0      1      [::ffff:127.0.0.1]:8005                         [::]:*                  
LISTEN      0      100              
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值