问题描述
我正在尝试在nodejs代理应用程序之前设置nginx代理,以便在docker中使用AWS Elasticsearch应用程序.
I am trying to set up nginx proxy in front of nodejs proxy app to aws elasticsearch app in a docker.
第一个容器侦听端口9100,另一个容器侦听端口9200
the first container is listen to port 9100, and the other one listen to port 9200
tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 26499/docker-proxy
tcp 0 0 127.0.0.1:9200 0.0.0.0:* LISTEN 4899/docker-proxy
当我转到http://my.domain.com/_plugin/kibana
nginx代理到http://127.0.0.1:9200/_plugin/kibana
时,位置根/
正常工作.
Location root /
works properly, when I go to http://my.domain.com/_plugin/kibana
nginx proxy to http://127.0.0.1:9200/_plugin/kibana
.
位置/kibana-test
不起作用,如果我去http://my.domain.com/kibana-test/_plugin/kibana
,我会得到404
.
Location /kibana-test
doesnt work, I get 404
if I go to http://my.domain.com/kibana-test/_plugin/kibana
.
知道为什么吗?
谢谢
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
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"'
'$uri $request_uri'
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
location = / {
proxy_set_header X-Real-IP 10.10.10.1;
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;
}
location /kibana-test/?(.*) {
proxy_set_header X-Real-IP 10.10.10.1;
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:9100;
}
}
}
错误日志调试:
2017/01/31 11:44:49 [debug] 15308#15308: *1 post event 00005597376E5B30
2017/01/31 11:44:49 [debug] 15308#15308: *1 post event 00005597376F7B40
2017/01/31 11:44:49 [debug] 15308#15308: *1 delete posted event 00005597376E5B30
2017/01/31 11:44:49 [debug] 15308#15308: *1 http keepalive handler
2017/01/31 11:44:49 [debug] 15308#15308: *1 malloc: 00005597376D53B0:1024
2017/01/31 11:44:49 [debug] 15308#15308: *1 recv: fd:8 368 of 1024
2017/01/31 11:44:49 [debug] 15308#15308: *1 reusable connection: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 posix_memalign: 00005597376C7F70:4096 @16
2017/01/31 11:44:49 [debug] 15308#15308: *1 event timer del: 8: 1485863133868
2017/01/31 11:44:49 [debug] 15308#15308: *1 http process request line
2017/01/31 11:44:49 [debug] 15308#15308: *1 http request line: "GET /kibana-test/_plugin/kibana HTTP/1.1"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http uri: "/kibana-test/_plugin/kibana"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http args: ""
2017/01/31 11:44:49 [debug] 15308#15308: *1 http exten: ""
2017/01/31 11:44:49 [debug] 15308#15308: *1 http process request header line
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header: "Host: my.domain.com"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header: "Accept-Language: en-US,en;q=0.5"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header: "Accept-Encoding: gzip, deflate"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header: "Connection: keep-alive"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header: "Upgrade-Insecure-Requests: 1"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http header done
2017/01/31 11:44:49 [debug] 15308#15308: *1 generic phase: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 rewrite phase: 1
2017/01/31 11:44:49 [debug] 15308#15308: *1 test location: "/"
2017/01/31 11:44:49 [debug] 15308#15308: *1 test location: "kibana-test/?(.*)"
2017/01/31 11:44:49 [debug] 15308#15308: *1 using configuration "/"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http cl:-1 max:1048576
2017/01/31 11:44:49 [debug] 15308#15308: *1 rewrite phase: 3
2017/01/31 11:44:49 [debug] 15308#15308: *1 post rewrite phase: 4
2017/01/31 11:44:49 [debug] 15308#15308: *1 generic phase: 5
2017/01/31 11:44:49 [debug] 15308#15308: *1 generic phase: 6
2017/01/31 11:44:49 [debug] 15308#15308: *1 generic phase: 7
2017/01/31 11:44:49 [debug] 15308#15308: *1 access phase: 8
2017/01/31 11:44:49 [debug] 15308#15308: *1 access phase: 9
2017/01/31 11:44:49 [debug] 15308#15308: *1 access phase: 10
2017/01/31 11:44:49 [debug] 15308#15308: *1 post access phase: 11
2017/01/31 11:44:49 [debug] 15308#15308: *1 posix_memalign: 00005597376BABD0:4096 @16
2017/01/31 11:44:49 [debug] 15308#15308: *1 http init upstream, client timer: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 http script copy: "X-Real-IP: 10.10.10.1
2017/01/31 11:44:49 [debug] 15308#15308: *1 http script copy: "Connect: Keep-Alive
2017/01/31 11:44:49 [debug] 15308#15308: *1 http script copy: "Proxy-Connection: Keep-Alive
2017/01/31 11:44:49 [debug] 15308#15308: *1 http script copy: "Host: "
2017/01/31 11:44:49 [debug] 15308#15308: *1 http script var: "127.0.0.1:9200"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http script copy: "
2017/01/31 11:44:49 [debug] 15308#15308: *1 http script copy: "Connection: close
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "Accept-Language: en-US,en;q=0.5"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "Accept-Encoding: gzip, deflate"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "Upgrade-Insecure-Requests: 1"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header:
"GET /kibana-test/_plugin/kibana HTTP/1.1
X-Real-IP: 10.10.10.1
Connect: Keep-Alive
Proxy-Connection: Keep-Alive
Host: 127.0.0.1:9200
Connection: close
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Upgrade-Insecure-Requests: 1
"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http cleanup add: 00005597376BB4A8
2017/01/31 11:44:49 [debug] 15308#15308: *1 get rr peer, try: 1
2017/01/31 11:44:49 [debug] 15308#15308: *1 stream socket 9
2017/01/31 11:44:49 [debug] 15308#15308: *1 epoll add connection: fd:9 ev:80002005
2017/01/31 11:44:49 [debug] 15308#15308: *1 connect to 127.0.0.1:9200, fd:9 #4
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream connect: -2
2017/01/31 11:44:49 [debug] 15308#15308: *1 posix_memalign: 00005597376B6630:128 @16
2017/01/31 11:44:49 [debug] 15308#15308: *1 event timer add: 9: 60000:1485863149318
2017/01/31 11:44:49 [debug] 15308#15308: *1 http finalize request: -4, "/kibana-test/_plugin/kibana?" a:1, c:2
2017/01/31 11:44:49 [debug] 15308#15308: *1 http request count:2 blk:0
2017/01/31 11:44:49 [debug] 15308#15308: *1 delete posted event 00005597376F7B40
2017/01/31 11:44:49 [debug] 15308#15308: *1 http run request: "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream check client, write event:1, "/kibana-test/_plugin/kibana"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream recv(): -1 (11: Resource temporarily unavailable)
2017/01/31 11:44:49 [debug] 15308#15308: *1 post event 00005597376F7BA0
2017/01/31 11:44:49 [debug] 15308#15308: *1 delete posted event 00005597376F7BA0
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream request: "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream send request handler
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream send request
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream send request body
2017/01/31 11:44:49 [debug] 15308#15308: *1 chain writer buf fl:1 s:415
2017/01/31 11:44:49 [debug] 15308#15308: *1 chain writer in: 00005597376BB4E0
2017/01/31 11:44:49 [debug] 15308#15308: *1 writev: 415 of 415
2017/01/31 11:44:49 [debug] 15308#15308: *1 chain writer out: 0000000000000000
2017/01/31 11:44:49 [debug] 15308#15308: *1 event timer del: 9: 1485863149318
2017/01/31 11:44:49 [debug] 15308#15308: *1 event timer add: 9: 60000:1485863149318
2017/01/31 11:44:49 [debug] 15308#15308: *1 post event 00005597376E5B90
2017/01/31 11:44:49 [debug] 15308#15308: *1 post event 00005597376F7BA0
2017/01/31 11:44:49 [debug] 15308#15308: *1 delete posted event 00005597376E5B90
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream request: "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream process header
2017/01/31 11:44:49 [debug] 15308#15308: *1 malloc: 00005597376BBBE0:4096
2017/01/31 11:44:49 [debug] 15308#15308: *1 recv: fd:9 559 of 4096
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy status 404 "404 Not Found"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "X-Powered-By: Express"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "access-control-allow-origin: *"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "content-type: application/json; charset=UTF-8"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "content-length: 331"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "connection: Close"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "Vary: Accept-Encoding"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header: "Date: Tue, 31 Jan 2017 11:44:49 GMT"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy header done
2017/01/31 11:44:49 [debug] 15308#15308: *1 xslt filter header
2017/01/31 11:44:49 [debug] 15308#15308: *1 HTTP/1.1 404 Not Found
Server: nginx/1.10.0 (Ubuntu)
Date: Tue, 31 Jan 2017 11:44:49 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 331
Connection: keep-alive
X-Powered-By: Express
access-control-allow-origin: *
Vary: Accept-Encoding
2017/01/31 11:44:49 [debug] 15308#15308: *1 write new buf t:1 f:0 00005597376BB7F0, pos 00005597376BB7F0, size: 264 file: 0, size: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 http write filter: l:0 f:0 s:264
2017/01/31 11:44:49 [debug] 15308#15308: *1 http cacheable: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 http proxy filter init s:404 h:0 c:0 l:331
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream process upstream
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe read upstream: 1
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe preread: 331
2017/01/31 11:44:49 [debug] 15308#15308: *1 readv: 1, last:3537
2017/01/31 11:44:49 [debug] 15308#15308: *1 readv() not ready (11: Resource temporarily unavailable)
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe recv chain: -2
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe buf free s:0 t:1 f:0 00005597376BBBE0, pos 00005597376BBCC4, size: 331 file: 0, size: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe length: 331
2017/01/31 11:44:49 [debug] 15308#15308: *1 input buf #0
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe write downstream: 1
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe write downstream flush in
2017/01/31 11:44:49 [debug] 15308#15308: *1 http output filter "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http copy filter: "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 image filter
2017/01/31 11:44:49 [debug] 15308#15308: *1 xslt filter body
2017/01/31 11:44:49 [debug] 15308#15308: *1 http postpone filter "/kibana-test/_plugin/kibana?" 00005597376BBA30
2017/01/31 11:44:49 [debug] 15308#15308: *1 write old buf t:1 f:0 00005597376BB7F0, pos 00005597376BB7F0, size: 264 file: 0, size: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 write new buf t:1 f:0 00005597376BBBE0, pos 00005597376BBCC4, size: 331 file: 0, size: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 http write filter: l:0 f:0 s:595
2017/01/31 11:44:49 [debug] 15308#15308: *1 http copy filter: 0 "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 pipe write downstream done
2017/01/31 11:44:49 [debug] 15308#15308: *1 event timer: 9, old: 1485863149318, new: 1485863149382
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream exit: 0000000000000000
2017/01/31 11:44:49 [debug] 15308#15308: *1 finalize http upstream request: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 finalize http proxy request
2017/01/31 11:44:49 [debug] 15308#15308: *1 free rr peer 1 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 close http upstream connection: 9
2017/01/31 11:44:49 [debug] 15308#15308: *1 free: 00005597376B6630, unused: 48
2017/01/31 11:44:49 [debug] 15308#15308: *1 event timer del: 9: 1485863149318
2017/01/31 11:44:49 [debug] 15308#15308: *1 delete posted event 00005597376F7BA0
2017/01/31 11:44:49 [debug] 15308#15308: *1 reusable connection: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 http upstream temp fd: -1
2017/01/31 11:44:49 [debug] 15308#15308: *1 http output filter "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http copy filter: "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 image filter
2017/01/31 11:44:49 [debug] 15308#15308: *1 xslt filter body
2017/01/31 11:44:49 [debug] 15308#15308: *1 http postpone filter "/kibana-test/_plugin/kibana?" 00007FFDFE6952B0
2017/01/31 11:44:49 [debug] 15308#15308: *1 write old buf t:1 f:0 00005597376BB7F0, pos 00005597376BB7F0, size: 264 file: 0, size: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 write old buf t:1 f:0 00005597376BBBE0, pos 00005597376BBCC4, size: 331 file: 0, size: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 write new buf t:0 f:0 0000000000000000, pos 0000000000000000, size: 0 file: 0, size: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 http write filter: l:1 f:0 s:595
2017/01/31 11:44:49 [debug] 15308#15308: *1 http write filter limit 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 writev: 595 of 595
2017/01/31 11:44:49 [debug] 15308#15308: *1 http write filter 0000000000000000
2017/01/31 11:44:49 [debug] 15308#15308: *1 http copy filter: 0 "/kibana-test/_plugin/kibana?"
2017/01/31 11:44:49 [debug] 15308#15308: *1 http finalize request: 0, "/kibana-test/_plugin/kibana?" a:1, c:1
2017/01/31 11:44:49 [debug] 15308#15308: *1 set http keepalive handler
2017/01/31 11:44:49 [debug] 15308#15308: *1 http close request
2017/01/31 11:44:49 [debug] 15308#15308: *1 http log handler
2017/01/31 11:44:49 [debug] 15308#15308: *1 posix_memalign: 00005597376BCBF0:4096 @16
2017/01/31 11:44:49 [debug] 15308#15308: *1 free: 00005597376BBBE0
2017/01/31 11:44:49 [debug] 15308#15308: *1 free: 00005597376C7F70, unused: 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 free: 00005597376BABD0, unused: 104
2017/01/31 11:44:49 [debug] 15308#15308: *1 free: 00005597376BCBF0, unused: 3856
2017/01/31 11:44:49 [debug] 15308#15308: *1 free: 00005597376D53B0
2017/01/31 11:44:49 [debug] 15308#15308: *1 hc free: 0000000000000000 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 hc busy: 0000000000000000 0
2017/01/31 11:44:49 [debug] 15308#15308: *1 reusable connection: 1
2017/01/31 11:44:49 [debug] 15308#15308: *1 event timer add: 8: 65000:1485863154382
2017/01/31 11:44:49 [debug] 15308#15308: *1 post event 00005597376E5B30
2017/01/31 11:44:49 [debug] 15308#15308: *1 delete posted event 00005597376E5B30
2017/01/31 11:44:49 [debug] 15308#15308: *1 http keepalive handler
2017/01/31 11:44:49 [debug] 15308#15308: *1 malloc: 00005597376D53B0:1024
2017/01/31 11:44:49 [debug] 15308#15308: *1 recv: fd:8 -1 of 1024
2017/01/31 11:44:49 [debug] 15308#15308: *1 recv() not ready (11: Resource temporarily unavailable)
2017/01/31 11:44:49 [debug] 15308#15308: *1 free: 00005597376D53B0
推荐答案
我认为您需要将location =/kibana-test放在location =/之前,因为否则,nginx将获得其第一个匹配项,并且将不再匹配
I think you need to put the location= /kibana-test before the location= /, Because otherwise nginx will get its first match and will not match further
这篇关于Nginx位置指令不适用于Node.js代理应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!