如果我保持default http://127.0.0.1:9200
取消注释,proxy_pass
可以工作,但是使用下面映射到~^/kibana-dev
的代码,proxy_pass
不能工作,如果我转到http://my.domain.com/kibana-dev
,我会得到500
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"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
map $request_uri $target {
#default http://127.0.0.1:9200;
~^/kibana-dev http://127.0.0.1:9200;
~^/kibana-test http://127.0.0.1:9100;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
if ( $request_uri ~* ^/kibana-test ) {
return 301 http://my.domain.com/_plugin/kibana;
}
if ( $request_uri ~* ^/kibana-dev ) {
return 301 http://my.domain.com/_plugin/kibana;
}
location / {
proxy_set_header X-Real-IP 1.2.3.4;
proxy_http_version 1.1;
proxy_set_header Connect "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
proxy_set_header Authorization "";
proxy_pass $target;
}
}
}
我也试过了:
map $uri $target {
/kibana-dev http://127.0.0.1:9200;
}
知道为什么吗?谢谢
发布于 2017-01-30 17:02:02
您的配置文件没有任何意义。
如果提供URI http://my.domain.com/kibana-dev
,server
块将执行:
return 301 http://my.domain.com/_plugin/kibana;
这会导致URI被表示为/_plugin/kibana
。新的URI由location /
块处理并执行:
proxy_pass $target;
此时,咨询map
以确定$target
的值,该值是default
的值,因为/_plugin/kibana
与任何其他值都不匹配。
https://stackoverflow.com/questions/41940640
复制相似问题