3

我在我的 ec2 实例上使用 monit,我是 nginx 的新手。下面是我的 nginx 配置文件:

server {
  listen 80;
  server_name 127.0.0.1;
  location / {
    proxy_pass 127.0.0.1:2812;
    proxy_set_header Host $host;
  }
}

所以..如果我去 domain.com 我会看到 monit。如何修改上面的代码,我可以在 domain.com/monit 上看到 monit?

谢谢

4

3 回答 3

10

请试试这个:

server {
  listen 80;
  server_name 127.0.0.1;

  location /monit/ {
    proxy_pass http://127.0.0.1:2812;
    proxy_set_header Host $host;
  }

}

在此处阅读有关指令位置在 nginx 中的工作原理的更多信息

于 2012-02-01T14:18:33.870 回答
5

Monit 的wiki中有一篇文章如何使用 Nginx 进行配置。

这是我的/etc/nginx/conf.d/monit.conf

server {
    listen   80;
    server_name  my.server.name;

    location /monit/ {
            allow 127.0.0.1;
            allow 192.0.0.0/8;
            deny all;

            proxy_pass http://127.0.0.1:2812;
            proxy_set_header Host $host;
            rewrite ^/monit/(.*) /$1 break;
            proxy_ignore_client_abort on;
    }
}
于 2015-01-19T10:36:34.733 回答
1

谢尔盖已经正确回答了您的直接问题。我认为还值得注意的是,仅使用子域可能会更干净:

server {
  listen 80;
  server_name monit.domain.com;
  location / {
    proxy_pass 127.0.0.1:2812;
    proxy_set_header Host $host;
  }
}
于 2014-03-17T17:09:29.667 回答