简体   繁体   中英

Nginx M/Monit password protect

I am trying to protect access to M/Monit web interface:
Box:
ubuntu 14.04
nginx 1.8.1
mmonit-3.5.1

I created a mmonit config file under /etc/nginx/sites-available :

server {
        listen 8080;
        root /var/www/html;
        location / {
                auth_basic "Restricted Content";
                auth_basic_user_file /etc/nginx/.htpasswd;
        }

        location ~ /\.ht {
                deny all;
        }

}

It does not display the authentication dialog. I followed serverfault-Nginx Password Protect Entire Port Number 8081 , but it seems I am getting something done wrong...I am new to nginx.

Anyone has an idea how to go about it? Should it be in the same default server config file? Cheers

So I figured it out...
(This is under default server config)

root /var/www/html/;
server_name localhost;

location /mmonit/ {
    proxy_pass http://yourServerIp:8080/;
    auth_basic "Restricted Content";
    auth_basic_user_file /path/to/your/password/file/;
    index index.csp;
}

ln -s /path/to/your/mmonit/folder/ /var/www/html/
Gives: mmonit -> /path/to/your/mmonit/folder/

Now point you browser at: http://yourServerIp/mmonit/
And you will have the 'Authentication Required' dialog box!
A username and password are being requested by http://yourServerIp. The site says: "Restricted Content"

**I do suggest calling the link something else then mmonit....to your choice.
Any wayz your access is now double protected!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM