我有一个主服务器,主要用于自托管的应用程序(notes,git server,Jenkins server,等等),我想组织这个主服务器,这样我就不必记住每个容器的所有端口。
我希望根端点路由到一个运行google的cadvisor的容器,以监视我所有容器的状态,/jenkins路由到Jenkins,/pihole路由到pi-hole,等等。
下面是我如何根据我对配置模式的理解来设置我的docker-compose和nginx.conf文件:
docker-compose.yml:
version: '3'
services:
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
restart: unless-stopped
cadvisor:
image: 'google/cadvisor'
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
ports:
- "8090:8090"
pi-hole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
- "8070:8070/tcp"
- "4437:4437/tcp"
environment:
TZ: 'America/Chicago'
# WEBPASSWORD: 'set a secure password here or it will be random'
# Volumes store your data between container upgrades
volumes:
- './etc-pihole/:/etc/pihole/'
- './etc-dnsmasq.d/:/etc/dnsmasq.d/'
dns:
- 127.0.0.1
- 1.1.1.1
# Recommended but not required (DHCP needs NET_ADMIN)
# https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
cap_add:
- NET_ADMIN
restart: unless-stopped
cowyo:
image: 'schollz/cowyo'
ports:
- "8050:8050"
volumes:
- './cowyo/data/:/data/'
restart: unless-stopped
jenkins:
image: 'bitnami/jenkins:2'
ports:
- '8080:8080'
- '8443:8443'
- '50000:50000'
volumes:
- 'jenkins_data:/bitnami'
restart: unless-stopped
volumes:
jenkins_data:
driver: local
nginx.conf:
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
upstream docker-cadvisor {
server cadvisor:8090;
}
upstream docker-pihole {
server pi-hole:8070;
}
upstream docker-cowyo {
server cowyo:8050;
}
upstream docker-jenkins {
server jenkins:8080;
}
server {
listen 80;
location / {
proxy_pass http://docker-cadvisor;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
server {
listen 80;
location /pihole {
proxy_pass http://docker-pihole;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
server {
listen 80;
location /cowyo {
proxy_pass http://docker-cowyo;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
server {
listen 80;
location /jenkins {
proxy_pass http://docker-jenkins;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
你知道我做错了什么吗?任何帮助都将不胜感激。
编辑:它现在运行方式的问题是,当我去上面的一个网址,我得到一个“这个网站不能到达”的错误。
Edit 2:上面的问题是由一个坏的nginx.conf文件引起的,该文件导致Docker容器无法正常启动。解决该问题后,我得到一个“502坏网关”。
2条答案
按热度按时间kzmpq1sx1#
你得到的错误是什么?Tre下面的配置,如果你没有得到预期的结果,然后查看相应的错误日志.
thtygnil2#
我觉得你应该换个