Run Kibana behind Nginx proxy with basic authentication Kibana

Run Kibana behind Nginx proxy with basic authentication

Steps to run Kibana behind Nginx Proxy

To run Kibana behind Nginx proxy with basic authentication is really let’s go through the steps below

  1. Install Nginx
  2. Enable basic authentication
  3. Route Nginx to Kibana

Install nginx

sudo apt-get install nginx

To enable basic authentication, we need to create a username and password. We are using the apache2-utils package. Which helps us to create a user. Install it if you don’t have already.

Install apache2-utils

sudo apt-get install apache2-utils

Now, create a user with following command:

 htpasswd -c /etc/nginx/.htpasswd admin

It will ask you to enter a new password and confirm the password for the user admin. You will see a similar kid of message in your terminal.

root@ip-10-1-0-199:~# htpasswd -c /etc/nginx/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin

Now, the user creation is complete.

Now we need to configure nginx for kibana. Hence,

Edit the file like below:

Note: If you want to keep the backup of the original config file. Then you can execute the following command before editing the config file for Kibana. You can simply execute the following command.

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/original_backup_default

Edit config file

sudo vim /etc/nginx/sites-available/default

And paste the following code

server {
    listen 80;
    server_name localhost;
    auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/.htpasswd;
    location / {
        proxy_pass http://localhost:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Save it.

You can test whether the configuration is correct or not. With following command:

nginx -t

If the configuration is correct then you will see the message like:

root@ip-10-1-0-199:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload the nginx service

sudo service nginx reload

Conclusion

We are successfully configured the nginx for Kibana.


Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments