Tomcat deploys Springboot application, nginx acts as a proxy

ready:

① One cloud server

② Documents required for the experiment: https://pan.baidu.com/s/1TB93VTv4MfAu0g67LyUrnw to obtain the extraction code, please leave a message

③ Close the firewall, close selinux, cloud server security group and release the required ports

④ Note: If you turn on the firewall and selinux and set firewalld accordingly, selinux hardly needs to be changed

1. Upload all components to the /root directory: tomcat8, jdk8, website package zhwx-1.0.0, etc.

2. Install the required software

2.1 Install jdk

# 解压jdk
tar  -zxvf  /root/jdk-8u11-linux-x64.tar.gz

# 将jdk安装到/usr/local目录下
mv  /root/jdk1.8.0_11/   /usr/local/

# 配置环境变量,是java生效
vim /etc/profile

# 在profile文件末尾添加如下代码
JAVA_HOME=/usr/local/jdk1.8.0_11
PATH=/usr/local/jdk1.8.0_11/bin:$PATH
export  JAVA_HOME  PATH

# 保存、退出、刷新环境变量,也可以使用  . /etc/profile
source   /etc/profile

# 测试java环境安装是否成功
java
javac
java   -version

2.2 Install tomcat 

# 解压tomcat
unzip /root/apache-tomcat-8.5.46.zip 

# 将tomcat安装到/usr/local目录下
mv  /root/apache-tomcat-8.5.46   /usr/local/tomcat8
# 进入到tomcat目录,修改bin目录,修改.sh文件让它们可以被执行
cd /usr/local/tomcat8/

# 递归将bin目录下的所有文件赋予可执行权限
chmod  -R 755   bin/

# 进入bin目录
cd  bin

#启动tomcat
./start.sh

2.3 Browser visit tomcat homepage: http://your IP address: port

2.4 Install mariadb 

# 安装mariadb
yum  install mariadb  mariadb-server  -y

# 启动
systemctl  start  mariadb

# 初始化
mysql_secure_installation

# 登录mysql
mysql  -uroot  -p

# 下边两条命令在mysql数据库执行
# 授权:给test授予全部权限,密码为123456
grant  all on  *.*  to test@'%'  identified by "123456";

# 创建数据库
create database  zhwxld;

# 应用zhwxld库
use  zhwxld;

# 导入数据
source  /root/zhwxld.sql

2.5 Install nginx

yum install  nginx

systemctl  start  nginx

systemctl  status  nginx

Third, deploy the website, first test the situation without an agent

3.1 modify tomcat configuration

# 将网站放到tomcat根站点下
mv  /root/zhwx-1.0.0  /usr/local/tomcat8/webapps/

# 修改tomcat 配置文件  
vim  /usr/local/tomcat8/conf/server.xml

# 改动一:tomcat访问端口改为8090(我用的电信天翼云,8080端口要备案)
 <Connector port="8090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

# 改动二:server.xml中添加下边这行
# Context元素代表在特定虚拟主机上运行的一个Web应用

# 我的理解是:如果没有下边这个配置,访问路径需要加/zhwx-1.0.0/
# 如果配置了下边这句,访问路径直接就是IP地址+端口号
<Context  path=""  docBase="zhwx-1.0.0"  debug="0" privileged="true"/>

 3.2 Modify the site's access to the database

# 下边的修改需要有一些开发经验
# 修改应用配置文件中的数据库用户名为test,密码为123456
vim  /usr/local/tomcat8/webapps/zhwx-1.0.0/WEB-INF/classes/application.yml

  

 3.3 Test visit effect

 Fourth, nginx acts as a proxy, add the nginxtomcat.conf file in the nginx configuration folder

# 添加nginx的配置文件
vim /etc/nginx/conf.d/nginxtomcat.conf


#  --------添加下面代码---------
server {
        listen       8085;
        server_name  localhost;
        client_max_body_size 1024M;

        location / {
            proxy_pass http://你的IP地址:8090/;
            proxy_set_header Host $host:$server_port;
       }

}
# 修改配置文件后,重启nginx
systemctl  restart  nginx

# 查看8085、8090端口监听状态
netstat  -antp

 

 

 Test access address: http://your IP address:8085/

Guess you like

Origin blog.csdn.net/qq_29644709/article/details/109778409