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

时间:2017-01-28 21:11:05

标签: node.js nginx docker proxy

我正在尝试将nginx代理设置为node.js代理到docker中的aws 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;
    }
}

当我去nginx.mydomain.com/es-kibana-dev时,我可以看到kibana页面,但它卡住了,我得到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}

我可以在我的localhost上正确看到索引 - 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"
}

我感觉nginx配置存在问题。

欢迎任何建议,

由于

2 个答案:

答案 0 :(得分:1)

以下各项对我有用:

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

访问(不要忘记尾随斜线):

答案 1 :(得分:0)

import org.apache.spark.SparkFiles

// you can also use `spark-submit --files=credential.p12`
sqlContext.sparkContext.addFile("credential.p12")
val credentialPath = SparkFiles.get("credential.p12")

val df = sqlContext.read.
    format("com.github.potix2.spark.google.spreadsheets").
    option("serviceAccountId", "xxxxxx@developer.gserviceaccount.com").
    option("credentialPath", credentialPath).
    load("<spreadsheetId>/worksheet1")

它适用于两者

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