如何阻止NGINX通过URL的标识部分发送?
我正在设置一个AWS实例来容纳我的prometheus和grafana服务器。我正在使用NGINX通过a/location在两个客户端之间进行路由。问题是,NGINX必须传递这个值,而客户端无法理解它 我的NGINX配置:如何阻止NGINX通过URL的标识部分发送?,nginx,prometheus,grafana,Nginx,Prometheus,Grafana,我正在设置一个AWS实例来容纳我的prometheus和grafana服务器。我正在使用NGINX通过a/location在两个客户端之间进行路由。问题是,NGINX必须传递这个值,而客户端无法理解它 我的NGINX配置: http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent &qu
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
server_names_hash_bucket_size 128;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name <aws instance url>;
location /grafana {
proxy_pass http://localhost:3000;
}
location /prometheus {
allow <my ip>;
deny all;
proxy_pass http://localhost:9090;
}
}
}
http{
日志格式主“$remote\u addr-$remote\u user[$time\u local]“$request””
“$status$body\u bytes\u sent”$http\u referer”
“$http_user_agent”“$http_x_forwarded_for””;
access\u log/var/log/nginx/access.log main;
发送文件到;
tcp_nopush on;
tcp_节点延迟开启;
保持生命超时65;
服务器名称\u散列\u存储桶\u大小128;
类型\散列\最大\大小4096;
包括/etc/nginx/mime.types;
默认_类型应用程序/八位字节流;
#从/etc/nginx/conf.d目录加载模块化配置文件。
#看http://nginx.org/en/docs/ngx_core_module.html#include
#了解更多信息。
包括/etc/nginx/conf.d/*.conf;
服务器{
听80;
听[:]:80;
服务器名称;
地点/格拉法纳{
代理通行证http://localhost:3000;
}
地点/普罗米修斯{
允许;
否认一切;
代理通行证http://localhost:9090;
}
}
}
所以当我导航到/grafana时。它成功地将我带到grafana,但grafana客户端尝试解析/grafana,但找不到它的页面,并返回404
有没有办法摆脱这个问题,还是我的做法完全错了?您是否需要在
/grafana
和/prometheus
之后保留URI的其余部分
如果是,则需要重写URI:
server {
...
location /grafana {
rewrite ^/grafana(.*)$ $1 break;
proxy_pass http://localhost:3000;
}
location /prometheus {
allow <my ip>;
deny all;
rewrite ^/prometheus(.*)$ $1 break;
proxy_pass http://localhost:9090;
}
}
我在这两个解决方案中找到了这个问题,这两个解决方案只允许prometheus和grafana在子路径后面运行,这样nginx就可以正常通过它: 对于普罗米修斯,使用
--web.externalURL=/prometheus/
标志集启动它:
对于Grafana,在配置中设置server.root_url:
在尝试“保留uri”时,您需要的是尾随/检查此选项(第二个解决方案不起作用,因为整个客户端都没有服务,当prometheus指向它的/graph页面时,它抛出一个404,因为nginx不知道如何查看prometheus)。我认为第一次修复会解决这个问题,但我得到一个500错误,即URI的长度为零
server {
...
location /grafana {
proxy_pass http://localhost:3000/; # Note the trailing slash here...
}
location /prometheus {
allow <my ip>;
deny all;
proxy_pass http://localhost:9090/; # ...and here
}
}