我正在将Docker用于Windows,并希望将nginx设置为反向代理。一切工作正常,但是如果我想为我的本地主机定义代理,则总是会出现502或504错误。我以为设置extra_host
可以解决我的问题,但没有解决。是否可以尝试将其他IP设置为主机,还是其他错误?docker-compose.yml:
version: '3'
volumes:
etc:
driver: local
services:
nginx:
container_name: nginx
image: nginx:latest
volumes:
- ./etc:/etc/nginx
ports:
- 8088:80
extra_hosts:
- localhost:127.0.0.1
nginx.conf:
user nginx;
worker_processes 1;
events {
}
http {
server {
listen 80;
server_name localhost;
location /auth {
proxy_pass http://localhost:8082/auth;
}
location /graphql {
proxy_pass http://localhost:8080/graphql;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_http_version 1.1;
}
location ^~ / {
proxy_pass http://localhost:8082/auth;
}
location /sso/login {
proxy_pass http://localhost:8082/auth;
}
}
}
PS:所有引用的路径都是docker容器,例如/auth
是密钥斗篷验证服务器
我自己解决了这个问题。如果打开docker设置(右键单击docker图标),则具有以下网络设置。默认情况下,DNS服务器设置为自动->将其更改为固定8.8.8.8然后,您可以使用10.0.75.2而不是localhost访问容器。最后但并非最不重要的一点,将此地址作为extra_host
添加到您的docker-compose文件中并启动它。
version: '3'
volumes:
etc:
driver: local
services:
nginx:
container_name: nginx
image: nginx:latest
volumes:
- ./etc:/etc/nginx
ports:
- 8088:80
extra_hosts:
- localhost:10.0.75.2