第一步:拉取nginx的官方镜像
镜像地址: https://hub.docker.com/search?q=nginx&type=image
使用NGINX的官方镜像,然后拉取到本地
执行docker images
如果有下面的信息则表示拉取成功
第二步:
nginx.conf文件如下
user nginx;
worker_processes auto;
# error_log /Users/mac/Desktop/nginx/log/error.log warn;
# pid /Users/mac/Desktop/nginx/nginx.pid;
events {
worker_connections 1024;
}
http {
server {
listen 80;
location /auth {
proxy_pass http://tomcats;
}
}
upstream tomcats{
server 192.168.8.81:8081;
server 192.168.8.81:8082;
server 192.168.8.81:8083;
}
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# access_log /Users/mac/Desktop/nginx/log/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
其中的几个注意点:
- upstream tomcats 配置的是本地的三个Springboot的应用,其中192.168.8.81为本地IP
- listen 80 是监听的Nginx的端口
- location /auth 是Springbootgc的
context-path
然后执行下面的命令即可
docker run -p 82:80 --name nginx1 -v /Users/mac/Desktop/nginx/nginx.conf:/etc/nginx/nginx.conf -d nginx