无法在容器中访问nginx url

时间:2014-11-11 20:56:49

标签: nginx vagrant docker graphite vagrantfile

我有以下设置

  1. 安装了泊坞窗的流浪盒

  2. Docker容器启动并运行

  3. 但是我无法从我的主机访问nginx config

    中指定的一个url

    我可以访问grafana一个

    我的流浪档案

    Vagrant.configure("2") do |config|
        config.vm.box = "dockerNoel"
        config.vm.box_url = "http://files.vagrantup.com/precise64.box"
        config.vm.provider :virtualbox do |virtualbox|
            # allocate 1024 mb RAM
            virtualbox.customize ["modifyvm", :id, "--memory", "2048"] 
            # allocate max 50% CPU
            virtualbox.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
          end
        # we'll forward the port 8000 from the VM to the port 8000 on the host (OS X)
        config.vm.network :forwarded_port, host: 80, guest: 80
        config.vm.network :forwarded_port, host: 8125, guest: 8125, protocol: 'udp'
        config.vm.network :forwarded_port, host: 8126, guest: 8126
        config.vm.network :forwarded_port, host: 9200, guest: 9200
        config.vm.network :forwarded_port, host: 9300, guest: 9300
    
        config.vm.provision "docker"
    end
    

    我的nginx配置文件

    daemon off;
    user www-data;
    worker_processes 1;
    pid /var/run/nginx.pid;
    
    events {
      worker_connections 1024;
    }
    
    http {
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      server_tokens off;
    
      server_names_hash_bucket_size 32;
    
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
    
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
    
      gzip on;
      gzip_disable "msie6";
    
      server {
        listen 80 default_server;
        server_name _;
        location / {
          root /src/grafana;
          index index.html;
        }
        location /graphite/ {
            proxy_pass                 http://127.0.0.1:8000/;
            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  $scheme;
            proxy_set_header           X-Forwarded-Server  $host;
            proxy_set_header           X-Forwarded-Host  $host;
            proxy_set_header           Host  $host;
    
            client_max_body_size       10m;
            client_body_buffer_size    128k;
    
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
    
            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
        }
    
        location /elasticsearch/ {
            proxy_pass                 http://127.0.0.1:9200/;
            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  $scheme;
            proxy_set_header           X-Forwarded-Server  $host;
            proxy_set_header           X-Forwarded-Host  $host;
            proxy_set_header           Host  $host;
    
            client_max_body_size       10m;
            client_body_buffer_size    128k;
    
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
    
            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
        }
      }
    
       server {
        listen 8888;
    
        location / {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
          proxy_pass http://localhost:5000/;
         }
    
        location /static/ {
          include       /etc/nginx/mime.types;
          default_type  application/octet-stream;
          root /cabot/;
        }
      }
    
      server {
        listen 81 default_server;
        server_name _;
    
        open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m;
    
        location / {
            proxy_pass                 http://127.0.0.1:8000;
            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  $scheme;
            proxy_set_header           X-Forwarded-Server  $host;
            proxy_set_header           X-Forwarded-Host  $host;
            proxy_set_header           Host  $host;
    
            client_max_body_size       10m;
            client_body_buffer_size    128k;
    
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
    
            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
        }
    
        add_header Access-Control-Allow-Origin "*";
        add_header Access-Control-Allow-Methods "GET, OPTIONS";
        add_header Access-Control-Allow-Headers "origin, authorization, accept";
    
        location /content {
          alias /var/lib/graphite/webapp/content;
        }
    
        location /media {
          alias /usr/share/pyshared/django/contrib/admin/media;
        }
      }
    }
    

    当我从主机浏览到http://127.0.0.1时,它可以工作 但是对于http://127.0.0.1/graphite/我找不到404

    当我在客人流浪者盒子中使用curl时,他们都工作

    我相信我在网络上做了一些愚蠢但却无法弄明白的事情

1 个答案:

答案 0 :(得分:0)

您的proxy_pass中有一个结尾斜杠。这意味着/graphite/将传递给后端。我怀疑石墨是从根部运行的,所以在后端没有找到uri。

请参阅proxy_pass上的文档:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass