我可以在Nginx中创建一个“私人”位置吗?

问题描述 投票:1回答:1

我可以在nginx config中创建一个可以由任何其他位置访问并且不能直接从外部访问的位置吗?

我可以使用deny指令,但是它也会拒绝访问nginx config中定义的位置。

这是我的配置-

server {
  listen *:80;
  server_name 127.0.0.1;

  location = /auth {
      set $query '';
      if ($request_uri ~* "[^\?]+\?(.*)$") {
         set $query $1;
      }
      # add_header X-debug-message "Parameters being passed $is_args$args" always;
      proxy_pass http://127.0.0.1:8080/auth?$query;
  }

  location /kibana/ {
     rewrite ^/kibana/(.*) /$1 break;
     proxy_pass http://127.0.0.1:5601;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection 'upgrade';
     proxy_set_header Host $host;
     proxy_set_header X-Forwarded-For $remote_addr;
     proxy_set_header  X-Real-IP  $remote_addr;
     proxy_cache_bypass $http_upgrade;
     auth_request /auth;
  }

  location ~ (/app/|/app/kibana|/bundles/|/kibana4|/status|/plugins|/ui/|/api/|/monitoring/|/elasticsearch/) {
     internal;
     proxy_pass http://127.0.0.1:5601;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     proxy_set_header Host $host;
     rewrite /kibana4/(.*)$ /$1 break;
  }

  error_page 404 /404.html;
    location = /40x.html {
  }

  error_page 500 502 503 504 /50x.html;
    location = /50x.html {
  }
}

因此,我只需要从/ kibana /位置访问最后一个位置,但是使用internal;会抛出404错误,但无法正常工作。

我实际上需要使用nginx保护kibana,但是无论如何我都将最终公开它而不进行任何身份验证。

nginx nginx-location nginx-config auth-request
1个回答
0
投票

您可以使用称为named location的名称。根本无法从外部访问它,但是在某些情况下,您可以在配置内部引用它:

location @nginxonly {
    proxy_pass http://example.com/$uri$is_args$args;
}

创建命名位置后,您可以在其他[[some]]中引用它,例如try_files指令中的最后一项。

© www.soinside.com 2019 - 2024. All rights reserved.