I'm trying to configure a nginx reverse proxy. I'm using htpasswd but it's unrelated in my case.
I want the following: when visit https://public-nginx/kibana I want that it redirects to the proxied url (to my private kibana), but it keeps the public-nginx URL.
My nginx.conf
looks pretty basic:
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
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;
server_names_hash_bucket_size 128;
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;
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name localhost;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
my conf.d/kibana.conf
looks like:
server {
listen 80;
server_name _;
location / {
proxy_pass https://private-url/kibana/;
proxy_redirect https://private-url/kibana/ /;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Authorization "";
proxy_hide_header Authorization;
auth_basic "Username and Password are required";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
When I check it seems that the /kibana
url is redirecting me to the right path (/kibana/app/..
). But I see a 404.
Drop
proxy_redirect https://private-url/kibana/ /;
from kibana.conf.It adds a 301 redirect to the private-url to all replies sent to the client, which is exactly what you are trying to avoid.
See http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
From your question it's not clear if you want kibana to be served from http://public-url/kibana or from http://public-url/
If you want it to be under http://public-url you also need to double check your
basePath
setting in kibana.yml. server.basePath enables you to specify a path to mount Kibana at if you are serving it from behind a reverse proxy. See https://www.elastic.co/guide/en/kibana/current/settings.html