繁体   English   中英

Docker中Nginx代理后面的node.js代理应用

[英]node.js proxy app in docker behind nginx proxy

我正在尝试将nginx代理设置为node.js代理,以在docker中将AWS Elasticsearch App设置为。

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: http://127.0.0.1:9200/_plugin/kibana/ 9200/_plugin/ 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}

我可以在我的本地主机-http: http://127.0.0.1:9200 :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配置上。

欢迎任何建议,

谢谢

以下代码块对我有用:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM