regex - NGINX 基本身份验证,代理内容的位置问题
问题描述
任务是阻止以下内容: /api/ldap-adapter/swagger-ui.html 在 NGINX default.conf 中,我们已经使用了以下位置:
location ~ /api(?<p_uri>.*) {
#https://serverfault.com/questions/240476/how-to-force-nginx-to-resolve-dns-of-a-dynamic-hostname-everytime-when-doing-p
set $gateway "http://tasks.gateway:8050";
proxy_pass $gateway$p_uri?$args;
proxy_intercept_errors on;
proxy_redirect off;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
当我只是尝试使用通配符或完全匹配来阻止它时:通配符:
location ~* \.html$ {
auth_basic "Administrator’s Area";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
完全符合:
location = /api/ldap-adapter/swagger-ui.html {
auth_basic "Administrator’s Area";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
我有以下错误:
2019/12/20 10:41:18 [error] 39#39: *39 open() "/usr/share/nginx/html/api/ldap-adapter/swagger-ui.html" failed (2: No such file or directory), client: 10.255.0.5, server: localhost, request: "GET /api/ldap-adapter/swagger-ui.html HTTP/1.1",
Nginx 使用一些默认的位置前缀:/usr/share/nginx/html..
例如,如何使用 swagger-ui 阻止所有内容?
解决方案
推荐阅读
- javascript - 我想通过 url 在 php 登陆页面中嵌入视频
- java - paintComponent() 和 paint() - 使用装饰器模式绘制 JButton
- javascript - 如何知道点击事件中点击了什么?
- amazon-web-services - AWS 使用用户池 JWT 从 Cognito 身份池获取凭证
- python - 在 GUI 中显示命令提示符窗口
- python - 带有线程的 Python HTTP 请求
- vue.js - SassError:`darken($color, $amount)` 的参数`$color` 必须是颜色
- java - 检测到 log4j-over-slf4j.jar 和 slf4j-log4j12.jar
- java - 为什么我们需要setRollbackOnly,而不仅仅是回滚事务?
- r - 在 R 中将 512 x 3 数据帧转换为 128 x 4 x 3 矩阵