Mah*_*ath 5 nginx auth-request nginx-location nginx-config
我可以创建一个位置,该位置可以被 nginx 配置中的任何其他位置访问,但不能从外部直接访问吗?
我可以使用拒绝指令,但它也会拒绝访问 nginx 配置中定义的位置。
这是我的配置 -
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 {
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我需要仅从位置 /kibana/ 访问最后一个位置,但internal;它会抛出 404 错误,否则它工作正常。
我实际上需要使用 nginx 来保护 kibana,但无论如何我最终都会在没有任何身份验证的情况下暴露它。
您可以使用称为命名位置的东西。它根本无法从外部访问,但在您的配置内部,您可以在某些情况下引用它:
location @nginxonly {
proxy_pass http://example.com/$uri$is_args$args;
}
Run Code Online (Sandbox Code Playgroud)
创建命名位置后,您可以在其他一些地方引用它,例如指令中的最后一项try_files。
| 归档时间: |
|
| 查看次数: |
2496 次 |
| 最近记录: |