gpt4 book ai didi

nginx 代理 ELK

转载 作者:行者123 更新时间:2023-12-04 17:42:04 30 4
gpt4 key购买 nike

我正在尝试代理运行 ELK 的后端服务器。这是我的环境信息:

root@proxy:~#
root@proxy:~# cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
root@proxy:~#
root@proxy:~# nginx -v
nginx version: nginx/1.14.0 (Ubuntu)
root@proxy:~#
root@proxy:~# cat /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

}
root@proxy:~#
root@proxy:~# cat /etc/nginx/conf.d/elk.conf
server {
listen 80;
server_name domain.tld;
return 301 https://$host$request_uri;
}

server {
listen 443 default_server ssl;
server_name domain.tld;

ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;

location / {
root /usr/share/nginx/html;
index index.html;
}

location /elk {
proxy_pass http://1.2.3.4:5601;
proxy_http_version 1.1;
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
}
}
root@proxy:~#

有了上面的配置,当我转到https://domain.tld ,我可以毫无问题地查看我的静态站点,但是当我转到 https://domain.tld/elk 时,我收到 404 Not Found。这是 404 的原始数据:

{"statusCode":404,"error":"Not Found","message":"Not Found"}

这是标题:

Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Fri, 04 Jan 2019 11:42:55 GMT
Server: nginx/1.14.0 (Ubuntu)
Transfer-Encoding: chunked
cache-control: no-cache
content-encoding: gzip
kbn-name: kibana
kbn-xpack-sig: d39f386737f81acb1fe7cc2cc4d80109
vary: accept-encoding

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
DNT: 1
Host: domain.tld
Referer: https://domain.tld/
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0

如果我这样配置:

root@proxy:~# cat /etc/nginx/conf.d/elk.conf
server {
listen 80;
server_name domain.tld;
return 301 https://$host$request_uri;
}

server {
listen 443 default_server ssl;
server_name domain.tld;

ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;

location / {
proxy_pass http://1.2.3.4:5601;
proxy_http_version 1.1;
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
}
}
root@proxy:~#

然后转到 https://domain.tld ,它将正确代理回 ELK 并且 Kibana 仪表板正确加载。

一直在修修补补,在线研究并相应地调整样本,但无法按照我想要的方式工作。感谢你的帮助。谢谢!

最佳答案

基本上,您需要进行两项更改才能解决问题。首先,请在 Nginx 服务器 block 文件中的 locationproxy_pass 指令的末尾添加斜杠,如下所示:

location /elk/ {
proxy_pass http://1.2.3.4:5601/;
proxy_http_version 1.1;
proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
}

其次,请取消注释 server.basePath 设置并在 kibana.yml 配置文件中提供 /elk 的值:

server.basePath: "/elk"

最后,您必须重新启动 Nginx 和 Kibana,然后再试一次。

关于nginx 代理 ELK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54038561/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com