我试图指向我的码头集装箱域名。在我们的路由器中,我们将端口80转发到192.168.1.101 (服务器码头正在运行)
然而,容器IP地址显示如下
"nextjs-docker-pm2-nginx-master-nextjs-1:172.18.0.2/16"
"nextjs-docker-pm2-nginx-master-nginx-1:172.18.0.4/16"CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cabb3c8fe03c nextjs-docker-pm2-nginx-master_nginx "/docker-entrypoint.…" 16 minutes ago Up 16 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nextjs-docker-pm2-nginx-master-nginx-1
ed27e0fd2f24 nextjs-docker-pm2-nginx-master_nextjs "docker-entrypoint.s…" 16 minutes ago Up 16 minutes 3000/tcp nextjs-docker-pm2-nginx-master-nextjs-1我的default.conf是
# Cache zone
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
upstream nextjs {
server nextjs:3000;
}
server {
listen 80;
server_name local.DOMAIN.com.au;
server_tokens off;
gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript image/svg+xml;
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;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
# BUILT ASSETS (E.G. JS BUNDLES)
# Browser cache - max cache headers from Next.js as build id in url
# Server cache - valid forever (cleared after cache "inactive" period)
location /_next/static {
proxy_cache STATIC;
proxy_pass http://nextjs;
}
# STATIC ASSETS (E.G. IMAGES)
# Browser cache - "no-cache" headers from Next.js as no build id in url
# Server cache - refresh regularly in case of changes
location /static {
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 60m;
proxy_pass http://nextjs;
}
# DYNAMIC ASSETS - NO CACHE
location / {
proxy_pass http://nextjs;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
}
}
server {
listen 443 default_server ssl http2;
server_name local.DOMAIN.com.au;
ssl_certificate /etc/nginx/ssl/live/local.domain.com.au/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/live/local.domain.com.au/privkey.pem;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
# BUILT ASSETS (E.G. JS BUNDLES)
# Browser cache - max cache headers from Next.js as build id in url
# Server cache - valid forever (cleared after cache "inactive" period)
location /_next/static {
proxy_cache STATIC;
proxy_pass http://nextjs;
}
# STATIC ASSETS (E.G. IMAGES)
# Browser cache - "no-cache" headers from Next.js as no build id in url
# Server cache - refresh regularly in case of changes
location /static {
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 60m;
proxy_pass http://nextjs;
}
# DYNAMIC ASSETS - NO CACHE
location / {
proxy_pass http://nextjs;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
}
}我们的停靠-撰写文件是
version: '3'
services:
nextjs:
build: ./DRN1Git
nginx:
user: $UID
build: ./nginx
restart: always
ports:
- 80:80
- 443:443
volumes:
- ./certbot/www:/var/www/certbot/:rw
- ./certbot/conf/:/etc/nginx/ssl/:ro
certbot:
image: certbot/certbot:latest
volumes:
- ./certbot/www/:/var/www/certbot/:rw
- ./certbot/conf/:/etc/letsencrypt/:rw发布于 2022-11-06 07:00:31
默认情况下,Docker创建内部网络。(在你的例子中是172.18.0.0/16)。您需要将容器的端口映射到您的码头主机(192.168.1.101)的外部。参考见组合端口。例如:
version: "3.9"
services:
web:
build: nginx
ports:
- "80:80"如果您提供您的docker-compose.yml文件,我将适合该示例以满足您的需要。
https://stackoverflow.com/questions/74332925
复制相似问题