tomcat+nginx简单配置
下载对应版本Tomcat、nginx安装包
服务器准备:
前端:192.168.206.135、192.168.206.136:7001
后端:192.168.206.134、192.168.206.138:7002
nginx前端:192.168.206.136:7021
nginx后端:192.168.206.134:7022
安装nginx
1
2
3
4
5tar -zxvf nginx.tar.gz #解压
cd nginx
./configure --with-http_stub_status_module --with-http_ssl_module #执行命令 考虑到后续安装ssl证书 添加两个模块
make
make install修改配置文件(默认安装位置:/usr/local/nginx)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28vim /usr/local/nginx/conf/nginx.conf
前端 代理
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
upstream optmsfront{
ip_hash;
server 192.168.206.135:7001;
server 192.168.206.136:7001;
}
sendfile on;
keepalive_timeout 65;
server {
listen 7021;
server_name 192.168.206.136;
location / {
proxy_pass http://optmsfront;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27后端代理
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
upstream optmsfront{
ip_hash;
server 192.168.206.134:7002;
server 192.168.206.138:7002;
}
sendfile on;
keepalive_timeout 65;
server {
listen 7022;
server_name 192.168.206.134;
location / {
proxy_pass http://optmsfront;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}解压Tomcat并修改配置文件
1
2tar -zxvf tomcat.tar.gz
vim /tomcat/conf/server.xml修改tomcat端口,前端服务器端口改为:7001,后端服务器的端口改为:7002
将编译后的项目放在tomcat/webapp下启动
1
nohup ./startup.sh &
启动nginx
1
2
3/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
重启nginx
/usr/local/nginx/sbin/nginx -s reload访问前端nginx测试是否成功
http://192.168.206.136:7021/项目名
- 标题: tomcat+nginx简单配置
- 作者: zlong.w
- 创建于 : 2023-09-26 15:17:43
- 更新于 : 2023-09-26 15:43:55
- 链接: https://zlonx.cn/2023/09/26/tomcat-nginx/
- 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。