docker后面的nginx代理中的node.js代理应用程序

我正在尝试将nginx代理设置为node.js代理,以便在docker中启用elasticsearch应用程序。

nginx version: nginx/1.10.0 - installed on the machine, not in docker Docker version 1.12.5, build 047e51b/1.12.5 CentOS Linux release 7.3.1611 (Core) docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -p 127.0.0.1:9200:9200 mydocker/es_kibana_proxy -b 0.0.0.0 search-elasticsearch-dev-tdxka.us-east-1.es.amazonaws.com 

netstat -nlp:

 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8431/nginx: master tcp 0 0 127.0.0.1:9200 0.0.0.0:* LISTEN 7963/docker-proxy-c 

它的作品,当我在我的本地计算机上运行容器,并通过浏览器没有nginx访问它 – http://127.0.0.1:9200/_plugin/kibana/

nginx.conf:

 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; include /etc/nginx/conf.d/*.conf; } 

conf.d]# cat default.conf

 server { listen 80; server_name nginx.mydomain.com; location / { root /usr/share/nginx/html; index index.html index.htm; } location /es-kibana-dev { proxy_pass http://127.0.0.1:9200/_plugin/kibana/; } location /es-dev { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:9200; proxy_redirect off; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } 

我可以看到kibana页面,当我去nginx.mydomain.com/es-kibana-dev ,但它坚持,我得到404,并在error.log下面的错误:

 [error] 8234#8234: *1 open() "/usr/share/nginx/html/styles/main.css" failed (2: No such file or directory), client: 12.12.12.1, server: nginx.mydomain.com, request: "GET /styles/main.css?_b=7562 HTTP/1.1", host: "nginx.mydomain.com", referrer: "http://nginx.mydomain.com/es-kibana-dev" error] 8234#8234: *1 open() "/usr/share/nginx/html/bower_components/requirejs/require.js" failed (2: No such file or directory), client: 12.12.12.1, server: nginx.mydomain.com, request: "GET /bower_components/requirejs/require.js?_b=7562 HTTP/1.1", host: "", referrer: "http://nginx.mydomain.com/es-kibana-dev" [error] 8234#8234: *3 open() "/usr/share/nginx/html/require.config.js" failed (2: No such file or directory), client: 12.12.12.1, server: nginx.mydomain.com, request: "GET /require.config.js?_b=7562 HTTP/1.1", host: "nginx.mydomain.com", referrer: "http://nginx.mydomain.com/es-kibana-dev" [error] 8234#8234: *4 open() "/usr/share/nginx/html/images/initial_load.gif" failed (2: No such file or directory), client: 12.12.12.1, server: nginx.mydomain.com, request: "GET /images/initial_load.gif HTTP/1.1", host: "nginx.mydomain.com", referrer: "http://nginx.mydomain.com/es-kibana-dev" 

我试图设置不同的代理es索引,我看到,当我去http://nginx.mydomain.com/es-dev

 {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"es-dev","index":"es-dev"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"es-dev","index":"es-dev"},"status":404} 

我可以正确地看到我的本地主机上的索引 – http://127.0.0.1:9200 ,没有nginx。

 { "name" : "Morbius", "cluster_name" : "elasticsearch-dev", "version" : { "number" : "2.3.2", "build_hash" : "72aa8010df1a4a359c9c588", "build_timestamp" : "2016-11-14T15:59:50Z", "build_snapshot" : false, "lucene_version" : "5.5.0" }, "tagline" : "You Know, for Search" } 

我有一个感觉nginxconfiguration的问题。

任何build议,欢迎,

谢谢

以下块为我工作:

 location /es-kibana-dev { rewrite ^/es-kibana-dev/(.*) /_plugin/kibana/$1 break; proxy_pass http://localhost:9200; } location /es-dev { rewrite ^/es-dev/(.*) /$1 break; proxy_pass http://127.0.0.1:9200; } 

访问(不要忘记最后的斜线):

 location / { proxy_set_header X-Real-IP *privare_ip; proxy_http_version 1.1; proxy_set_header Connect "Keep-Alive"; proxy_set_header Proxy-Connection "Keep-Alive"; proxy_set_header Authorization ""; proxy_pass http://127.0.0.1:9200; } 

它的作品都是

 http://my.domain.com/ => http://127.0.0.1:9200; http://my.domain.com/_plugin/kibana => http://127.0.0.1:9200/_plugin/kibana