Docker 安装Nginx
docker 安装nginx
先上docker-compose 配置
nginx:
#restart: always
image: nginx
container_name: nginx
ports:
- 80:80
- 443:443
links:
- tomcat:tomcat
volumes:
- /Users/docker/yz/nginx/nginx.conf:/etc/nginx/nginx.conf #配置文件
- /Users/docker/yz/nginx/conf.d:/etc/nginx/conf.d #配置文件
- /Users/docker/yz/nginx/log:/var/log/nginx #日志地址
- /Users/docker/yz/nginxWeb:/Users/docker/yz/nginxWeb #映射虚拟地址
tomcat:
image: tomcat:9.0
container_name: tomcat9.0
#restart: always
ports:
- 8080:8080
volumes:
- /Users/docker/yz/tomcat9.0/logs:/usr/local/tomcat/logs
- /Users/docker/yz/tomcat9.0/webapps:/usr/local/tomcat/webapps
-
nginx正向代理一直显示文件404,找不到文件地址,原因是没有在docker-compose.yml里面做映射
-
nginx反向代理需要在docker-compose.yml配置links 然后再在 nginx.conf 配置
upstream tomcat_client { server tomcat:8080 weight=1; } server { listen 80; location / { proxy_pass http://tomcat_client; index index.html index.htm; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
-
nginx docker使用反向代理
server_name 在mac中无法使用localhost,127.0.0.1
server {
listen 80;
server_name 192.168.3.33;
location / {
proxy_set_header Host $host;
proxy_pass http://192.168.3.33:8761;
}
}