[英]nginx: nginx reverse proxy works in server but not working on localhost
我有一個使用 prisma/graphql 的后端服務。 並且后端在端口 4001 上運行。這是我的 Nginx 配置文件proxy_pass:http://$host:4001
的代理通行證
當我從服務器運行它時,它同時適用於http://server:4001
和http://server
但是,當我從本地主機運行它時,我收到以下錯誤:
no resolver defined to resolve localhost, client: 172.30.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost"
是什么導致了這個錯誤以及如何解決它?
docker-compose:
backend:
image: base
command: >
sh -c "npm run deploy && npm run start"
env_file: ${ENV_FILE}
ports:
- '4001:4001'
depends_on:
- prisma
restart: always
volumes:
- ./deploy/certs:/deploy/certs
nginx:
image: nginx:latest
volumes:
- ./deploy/certs:/deploy/certs
- ./deploy/nginx/conf.d:/etc/nginx/conf.d
ports:
- 80:80/tcp
- 443:443/tcp
depends_on:
- backend
restart: always
env_file: ${ENV_FILE}
nginx 配置:
server {
listen 80 default_server;
server_name _;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://$host:4001;
}
}
我想您需要連接到nginx.conf
文件中docker-compose.yml
中指定的backend
服務。
例如
upstream localhost {
server backend:4001;
}
server {
listen 80;
server_name localhost;
}
你能試試這個嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.