请务必查看上期博客基础环境设置
参照内容截止至“#访问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