gpt4 book ai didi

Docker Nginx 主机无法解析

转载 作者:行者123 更新时间:2023-12-02 19:24:17 28 4
gpt4 key购买 nike

我正在尝试连接到已设置的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

    我做错了什么?

    最佳答案

    nginx 容器和上游服务器需要在同一个 docker 网络上。

    例子:
    假设 nginx 容器在网桥上暴露了 443 端口,创建一个名为 nginx-network 的 docker 网络并将其加入该网络。
    假设上游服务器是一个名为“mysite”的容器,将该容器加入 nginx-network,然后 nginx 将能够解析 dns“mysite”。

    关于Docker Nginx 主机无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57557163/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com