使用docker容器启动nginx转发失效的问题

使用docker容器启动nginx转发失效的问题

listen       80;
server_name  192.168.65.2;

# 首页
index index.html;

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

location /api/ {
    auth_request /auth;
    # 鉴权通过后的处理方式
    # ip必须配置为容器的宿主机ip
    proxy_pass http://192.168.65.2:8080/success;
}

location = /auth {
    # 发送子请求到HTTP服务,验证客户端的凭据,返回响应码
    internal;
    # 设置参数
    set $query '';
    if ($request_uri ~* "[^\?]+\?(.*)$") {
        set $query $1;
    }
    # 验证成功,返回200 OK
    proxy_pass http://192.168.65.2:8080/verify?$query;
    # 发送原始请求
    proxy_pass_request_body off;
    # 清空 Content-Type
    proxy_set_header Content-Type "";
 }

ip必须配置为容器的宿主机ip,否则会转发失败,一直404 NOT FOUND

404 NOT FOUND

获取宿主机ip方法(列举一种)

安装ping工具: apt-get install inetutils-ping

使用命令:

ping host.docker.internal

你可能感兴趣的:(docker,nginx)