0

I am trying to setup nginx proxy to node.js proxy to aws elasticsearch app in a docker.

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

Its works when I run the container on my local computer and access it via the browser without 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;
    }
}

I can see kibana page when I go to nginx.mydomain.com/es-kibana-dev, but its stuck and I get 404, and the below errors in 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"

I tried to set up differently the proxy to es index, and I see that when I go to 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}

I can see the the index properly on my localhost - http://127.0.0.1:9200, without 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"
}

I have a feeling the problems are with the nginx configuration.

any suggestions are welcome,

Thanks

2 Answers 2

1

The following blocks work for me:

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;
}

Visit (Don't forget the trailing slash):

Sign up to request clarification or add additional context in comments.

11 Comments

thanks, but I still have the same issue, if you want to know, I am using this docker container https://github.com/santthosh/aws-es-kibana and I want to access via nginx, if I curl inside the machine to local host curl http://localhost:9200 I can see the index, but from the browser I see errors, another idea ? thank you!
this is what I see from the browser, nginx proxy to the nodejs docker and its proxy to aws es
{"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}
curl within the server to localhost shows the container its working properly
curl http://localhost:9200 { "name" : "Warlock", "cluster_name" : "elasticsearch-dev", "version" : { "number" : "2.3.2", "build_hash" : "", "build_timestamp" : "", "build_snapshot" : false, "lucene_version" : "5.5.0" }, "tagline" : "You Know, for Search" }
|
0
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;
        }

Its works for both

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.