【问题标题】:Nginx M/Monit password protectNginx M/Monit 密码保护
【发布时间】:2016-02-06 15:26:46
【问题描述】:

我正在尝试保护对 M/Monit 网络界面的访问:
Box:
Ubuntu 14.04
nginx 1.8.1
mmonit-3.5.1

我在/etc/nginx/sites-available下创建了一个mmonit配置文件:

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

        location ~ /\.ht {
                deny all;
        }

}

它不显示身份验证对话框。 我关注了serverfault-Nginx Password Protect Entire Port Number 8081,但似乎我做错了什么……我是 nginx 新手。

有人知道怎么做吗? 它应该在同一个default 服务器配置文件中吗? 干杯

【问题讨论】:

  • 您是否包含来自/etc/nginx/nginx.conf 的sites-available?
  • @uzsolt 不,不需要....include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*;
  • 您在sites-enabled 中是否有指向mmonit.conf 的链接?我认为它应该工作。也许您可以尝试将您的代码复制到/etc/nginx/nginx.conf 并检查是否有效。
  • 您是否尝试添加到/etc/nginx/nginx.comf?日志呢?另一个琐碎的事情:您在浏览器中使用端口 8080 吗? :)
  • @uzsolt 我不认为问题出在nginx,更有可能是配置问题。由于M/Monit 是从一个包安装的,它不像一个网站,因此,我无法保护它的根文件夹,也无法保护它正在使用的端口8080 - 使用Nginx server block。当我尝试保护对端口 8080 的访问时,nginx 确实出错了 - [emerg] 20526#0: bind() to 0.0.0.0:8080 failed (98: Address already in use)

标签: nginx port monit


【解决方案1】:

所以我想通了...
(这是在默认服务器配置下)

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/
给出: mmonit -> /path/to/your/mmonit/folder/

现在将您的浏览器指向:http://yourServerIp/mmonit/
您将看到“需要身份验证”对话框!
A username and password are being requested by http://yourServerIp. The site says: "Restricted Content"

**我确实建议将链接称为其他名称,然后 mmoni.... 由您选择。
任何方式z 您的访问现在都受到双重保护!

【讨论】:

    猜你喜欢
    • 2015-10-19
    • 2011-05-18
    • 1970-01-01
    • 2015-10-20
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    相关资源
    最近更新 更多