使用 docker-compose 和 nginx 在 5 分钟内设置 Netbox
首先,为 netbox 及其所有数据创建一个目录。在此示例中,我们将使用 /opt/services/netbox.mydomain.com。将所有文件(除非另有说明)放在该目录中。
.env
显然,生成新密码并输入正确的域名。
netbox.env
SUPERUSER_EMAIL=[email protected]
SUPERUSER_PASSWORD=Soogohki0eidaQu4zaW9EjaBiuseeW
POSTGRES_PASSWORD=chied2EatoZ1EFeish1OixaiVee7ae
DOMAIN=netbox.mydomain.comdocker-compose.yml
你不需要在此修改任何内容(端口除外)
docker-compose.yml
services:
netbox-db:
image: postgres:15-alpine
restart: unless-stopped
volumes:
- ./pg_data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=netbox
- POSTGRES_USER=netbox
netbox-redis:
image: redis:7-alpine
user: 1000:1000
command: redis-server
restart: always
volumes:
- ./redis_data:/data
netbox:
image: lscr.io/linuxserver/netbox:latest
container_name: netbox
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Berlin
- SUPERUSER_EMAIL=${SUPERUSER_EMAIL}
- SUPERUSER_PASSWORD=${SUPERUSER_PASSWORD}
- ALLOWED_HOST=${DOMAIN}
- DB_NAME=netbox
- DB_USER=netbox
- DB_PASSWORD=${POSTGRES_PASSWORD}
- DB_HOST=netbox-db
- DB_PORT=5432
- REDIS_HOST=netbox-redis
- REDIS_PORT=6379
#- REDIS_PASSWORD=<REDIS_PASSWORD>
- REDIS_DB_TASK=0 # 任务的数据库 ID
- REDIS_DB_CACHE=1 # 缓存的数据库 ID
#- BASE_PATH=<BASE_PATH> #可选
#- REMOTE_AUTH_ENABLED=<REMOTE_AUTH_ENABLED> #可选
#- REMOTE_AUTH_BACKEND=<REMOTE_AUTH_BACKEND> #可选
#- REMOTE_AUTH_HEADER=<REMOTE_AUTH_HEADER> #可选
#- REMOTE_AUTH_AUTO_CREATE_USER=<REMOTE_AUTH_AUTO_CREATE_USER> #可选
#- REMOTE_AUTH_DEFAULT_GROUPS=<REMOTE_AUTH_DEFAULT_GROUPS> #可选
#- REMOTE_AUTH_DEFAULT_PERMISSIONS=<REMOTE_AUTH_DEFAULT_PERMISSIONS> #可选
volumes:
- ./netbox_config:/config
ports:
- 13031:8000
depends_on:
- netbox-db
- netbox-redis
restart: unless-stoppednginx 配置
将其放在例如 /etc/nginx/sites-enabled/netbox-mydomain.conf 中。
netbox.conf
server {
server_name netbox.mydomain.com;
location / {
proxy_pass http://localhost:13031/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_redirect default;
}
listen [::]:443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
}
server {
if ($host = netbox.mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name netbox.mydomain.com;
listen [::]:80; # managed by Certbot
return 404; # managed by Certbot
}之后,使用我们的脚本自动创建 systemd 服务并在启动时自动启动 Netbox:
create-docker-compose-service.sh
curl -fsSL https://techoverflow.net/scripts/create-docker-compose-service.sh | sudo bash /dev/stdin另外,重新加载 nginx 配置:
reload_nginx.sh
sudo service nginx reloadCheck out similar posts by category:
Networking
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow