Reputation: 75
I'm trying to proxy a backend server running ELK. Here's my environment info:
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:~#
With the above configurations, when I go to https://domain.tld, I can view my static site without issues but when I go to https://domain.tld/elk, I get a 404 Not Found. Here's the Raw Data of the 404:
{"statusCode":404,"error":"Not Found","message":"Not Found"}
Here's the Headers:
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
If I make my config as this:
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:~#
and go to https://domain.tld, it will proxy back to ELK correctly and the Kibana dashboard loads properly.
Been tinkering around, researched online and adjusted the samples accordingly but cannot make it to work the way I wanted. Appreciate your help. Thanks!
Upvotes: 4
Views: 1905
Reputation: 1457
Basically, you need to make two changes to solve the issue. First, please add slashes at the end of location
and proxy_pass
directive in Nginx server block file as follows:
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";
}
Second, please uncomment server.basePath
setting and give the value of /elk
in kibana.yml config file:
server.basePath: "/elk"
Finally, you must restart both Nginx and Kibana before giving it another try.
Upvotes: 2