docker run --name=nginx -p 9090:9090 -p 9091:9091 -d nginx
docker cp nginx:/etc/nginx/nginx.conf /root/java_project/tcm/tcm-service/conf/nginx.conf
原因:以防nginx.conf格式是文件夹导致挂载失败
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/json;
sendfile on;
keepalive_timeout 65;
server {
listen 9090;
# 指定nginx中前端项目所在的位置
location / {
root /usr/share/nginx/html/tcm-front;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# 反向代理
location /api {
rewrite /api/(.*) /$1 break;
# 对应后端接口路径
proxy_pass http://47.120.15.23:8888;
}
}
server {
listen 9091;
# 指定前端项目所在的位置
location / {
root /usr/share/nginx/html/tcm-back;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /prod-api {
rewrite /prodapi/(.*) /$1 break;
proxy_pass http://47.120.15.23:8880;
}
}
}
注意:
docker rm -f nginx
docker run -d \
--name nginx \
-p 9090:9090 \
-p 9091:9091 \
-v /root/java_project/tcm/tcm-service/tcm-ui:/usr/share/nginx/html \
-v /root/java_project/tcm/tcm-service/conf/nginx.conf:/etc/nginx/nginx.conf \
--network tcm \
nginx
前台网页:47.xxx.15.23:9090
后台网页:47.xxx.15.23:9091