【发布时间】:2019-12-24 16:45:39
【问题描述】:
我正在尝试连接到 docker 中的 proxypass 我已经设置但我不断收到:
8#8: *1 api.example.local could not be resolved (3: Host not found)
我可以通过在浏览器中转到http://api.example.com 来访问代理,但如果我通过 nginx 代理通行证则不能。我的nginx如下,请注意:
- 禁用 ipv6
-
我正在解析为 127.0.0.11
server { listen 80; server_name api.example.local; resolver 127.0.0.11 ipv6=off; location / { root /code/api/public_html/; index index.php index.html index.htm; try_files $uri $uri/ /index.php?rt=$uri&$args; } location ~ \.php$ { root /code/api/public_html/; fastcgi_pass php:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param ENV development; fastcgi_param HTTPS off; fastcgi_read_timeout 9600; }}
server { index index.php index.html; server_name www.example.local; resolver 127.0.0.11 ipv6=off; error_log /var/log/nginx/error.log; access_log /var/log/nginx/access.log; root /code/main/public_html; location / { root /code/main/public_html/; index index.php index.html index.htm; try_files $uri $uri/ /index.php?rt=$uri&$args; } location /api { resolver 127.0.0.11 ipv6=off; proxy_pass_header Set-Cookie; proxy_pass_header P3P; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Fowarded-Host $host; set $upstream api.example.local; proxy_pass http://$upstream; proxy_connect_timeout 60; proxy_redirect off; } location ~ \.php$ { root /code/main/public_html/; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param ENV development; fastcgi_param HTTPS off; fastcgi_read_timeout 300; }}
我的 /etc/hosts 中也有域。操作系统是 Ubuntu 18.04。
127.0.0.1 localhost
127.0.1.1 my-comp
127.0.0.1 www.example.local
127.0.0.1 api.example.local
我做错了什么?
【问题讨论】:
-
api.example.docker是否解析为主机以外的其他内容? -
不,它没有。我也在上面添加了我的 /etc/hosts 。 @7_R3X
-
127.0.0.11 位于主机网络中,因此 nginx 容器无法访问它。 Docker 创建了自己的网络(对我来说是 172.17.0.0/16 ),因此没有容器会识别超出此范围的主机。
标签: docker ubuntu nginx nginx-reverse-proxy