【问题标题】:Nginx Docker 400 Bad RequestNginx Docker 400 错误请求
【发布时间】:2017-06-07 11:25:59
【问题描述】:

我目前正在尝试将 nexus 托管为我组织内 docker 映像的私有注册表。我的 nginx 配置如下。

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    server {

            listen 6666;   ### Docker Hosted Repo HTTPS port
            server_name box.company.net;  ### Nexus Server
            keepalive_timeout 60;

            ssl on;
            ssl_certificate /etc/ssl/certs/nexus.crt;
            ssl_certificate_key /etc/ssl/certs/nexus.key;
            ssl_ciphers HIGH:!kEDH:!ADH:!MD5:@STRENGTH;
            ssl_session_cache shared:TLSSSL:16m;
            ssl_session_timeout 10m;
            ssl_prefer_server_ciphers on;

            client_max_body_size 0;
            chunked_transfer_encoding on;

            location /v2/ {


                    if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
                    return 404;
                    }
                    error_log               /var/log/nginx/error.log debug;
                    access_log              /var/log/nginx/docker.log;
                    proxy_set_header        Host $http_host;
                    proxy_set_header        X-Real-IP $remote_addr;
                    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header        X-Forwarded-Proto "https";
                    proxy_pass             http://box.company.net:4444/;
                    proxy_read_timeout      900;
        }

            location / {

                    error_log               /var/log/nginx/error.log debug;
                    access_log              /var/log/nginx/docker.log;
                    proxy_set_header        Host $http_host;
                    proxy_set_header        X-Real-IP $remote_addr;
                    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header        X-Forwarded-Proto "https";
                    proxy_pass              http://box.company.net:4444/;
                    proxy_read_timeout      90;
        }
    }

已使用 https 端口 6666 在 nexus(在端口 4444 上运行)配置了一个托管的 docker repo。

目前我们可以登录到 docker 注册表。

[test@server ~]$ docker login -u admin -p admin123 box.company.net:6666 登录成功

但是当我们尝试将标记的图像推送到 nexus 托管的 docker 注册表时,它会抛出 400 Bad Request 错误。

[test@server ~]$ docker push box.company.net:6666/alpine 推送是指存储库 [box.company.net:6666/alpine] 3fb66f713c9f:准备解析 HTTP 400 响应正文时出错:无效 字符 '\n \n https://box.company.net:6666/favicon-32x32.png?3.2.1-01\" 尺寸=\"32x32\">\n https://box.company.net:6666/safari-pinned-tab.svg?3.2.1-01\" color=\"#5bbad5\">\n https: //box.company.net:6666/favicon-16x16.png?3.2.1-01\" 尺寸=\"16x16\">\n https://box.company.net:6666/favicon.ico?3.2.1-01\">\n https://box.company.net:6666/mstile-144x144.png?3.2.1-01\">\n \n\n https://box.company.net:6666/static/css/nexus- content.css?3.2.1-01\"/>\n\n\n\n https://box.company.net:6666\">\n \n https://box.company.net:6666 /static/images/nexus.png?3.2.1-01\"/>\n \n \n \n Nexus 存储库管理器\n \n \n OSS 3.2.1-01\n \n \n \n\n\n\n \n https://box.company.net:6666/static/rapture/resources/icons/x32/exclamation.png?3.2.1-01\"/>\n 错误 400\n 错误请求\n \n \n \n
此 URL 不支持 HTTP 方法 POST\n \n
\n\n\n\n\n"

我是否遗漏了一些重要的 nginx 配置?还是我的请求格式不正确。

【问题讨论】:

  • 也许serverfault.com 是提出此类问题的更好地方。
  • 顺便说一句:在您的错误消息末尾,您可以找到“错误 400\n 错误请求\n \n \n \n HTTP 方法 POST 不受此 URL 支持”。也许这会引导你走向正确的方向。
  • 但它没有指定发布图片的网址
  • 那就看看我的第一条评论吧。
  • @reporter ok..我将在建议的链接上发布我的问题

标签: nginx docker nexus http-status-code-400 bad-request


【解决方案1】:

它现在工作。下面是我的 nginx 配置。

server {

    proxy_send_timeout 120;
    proxy_read_timeout 300;
    proxy_buffering    off;
    tcp_nodelay        on;

    server_tokens off;
    client_max_body_size 1G;

    listen 80;
    server_name box.company.net;
    location / {
          rewrite ^(.*) https://box.company.net$1 permanent;
    }
}

server {

    listen 443;
    server_name box.company.net;
    keepalive_timeout 60;
    ssl on;
    ssl_certificate /etc/ssl/certs/nexus.crt;
    ssl_certificate_key /etc/ssl/certs/nexus.key;
    ssl_ciphers HIGH:!kEDH:!ADH:!MD5:@STRENGTH;
    ssl_session_cache shared:TLSSSL:16m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;

    location / {

      proxy_set_header        Host $http_host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto "https";
      proxy_pass              http://box.company.net:8082;
      proxy_read_timeout      90;

    }
}

# correlates to your nexus http connector
server {

    listen 6666;
    server_name box.company.net;
    keepalive_timeout 60;
    ssl on;
    ssl_certificate /etc/ssl/certs/nexus.crt;
    ssl_certificate_key /etc/ssl/certs/nexus.key;
    ssl_ciphers HIGH:!kEDH:!ADH:!MD5:@STRENGTH;
    ssl_session_cache shared:TLSSSL:16m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;
    client_max_body_size 1G;
    chunked_transfer_encoding on;

    ### Block for Search,Pull,Push of Docker Images via Nexus Hosted Repo ####
    location / {

      access_log              /var/log/nginx/docker.log;
      proxy_set_header        Host $http_host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        if ($request_method !~* GET) {
                proxy_pass              http://box.company.net:4444;
        }
        if ($request_method = GET) {
                proxy_pass              http://box.company.net:5555;
        }
      proxy_read_timeout      90;
    }
}

【讨论】:

  • 谢谢。添加代理标头解决了这个问题。 proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto "https";
【解决方案2】:

推送图片时缺少命名空间。

查看文档 (https://books.sonatype.com/nexus-book/3.0/reference/docker.html#_accessing_repositories):

docker <command> <nexus-hostname>:<repository-port>/<namespace>/<image>:<tag>

你可以试试

docker push server.int.org.com:6666/alpine/alpine

【讨论】:

  • 还是同样的错误。 nginx配置正确吗??
猜你喜欢
  • 2014-02-19
  • 2017-05-28
  • 2014-08-03
  • 2018-11-28
  • 2016-04-07
  • 1970-01-01
  • 2015-06-17
  • 2020-06-06
  • 1970-01-01
相关资源
最近更新 更多