嗨,我需要一些帮助,如何设置自定义域,当我进入我的域时,我在 docker 中使用 nginx,它显示错误的网关
events {
worker_connections 1024;
}
http {
include /etc/nginx/sites-enabled/*;
}
server {
listen 80;
listen [::]:80;
server_name my-4portfolio.online;
location / {
proxy_pass http://frontend:3000;
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-Proto $scheme;
}
}
version: '3'
services:
frontend:
build:
context: ./client
ports:
- "3000:80"
nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites-enabled:/etc/nginx/sites-enabled
depends_on:
- frontend
我尝试部署React项目,它在103.253.72.246:3000上工作,我需要使用自定义域,我已经将nginx.conf和dns指向我的IP,但它不起作用
您可以在 docker-compose 文件中删除前端服务的端口绑定。由于您的 Nginx 服务器可以通过名称访问前端服务,因此请在 Nginx 配置中使用前端容器的默认端口(端口 80):
proxy_pass http://frontend/;
我不确定您目前如何通过该容器内的端口 80 为前端提供服务。但是,如果您只有前端应用程序,则可以将其构建为静态文件并直接从默认的 Nginx 位置提供它们。这样就不再需要 Nginx 之外的其他 Docker 镜像了。