这是我在这里使用的原始nginx配置,可以正常工作:
server {
listen 8080; # http
# Forward requests to our node app at port 8082
#
location /mui {
# Remove the '/mui' portion of the path (and any extraneous trailing slash)
rewrite ^/mui/?(.*)$ /$1; break;
proxy_pass http://localhost:8082;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location / {
# We also rewrite the Java servlet urls to move additional, 'RESTful' path elements
# to a url query parameter named '_path_suffix'
#
rewrite ^/(.*)$ /server?_path_suffix=$1; break;
proxy_pass http://localhost:8081;
proxy_redirect off;
}
}
我想对所有内容添加基本身份验证-除了一页以外... /mui/river
[如果我在服务器块中包括基本身份验证行,并将auth_basic off
放在location /mui
块中,则此配置可以按预期工作(它需要对/
进行身份验证,但不需要对/mui
进行身份验证:] >
server { listen 8080; # http auth_basic "Restricted Area"; auth_basic_user_file /etc/ngnix/.htpasswd; # Forward requests to our node app at port 8082 # location /mui { # Remove the '/mui' portion of the path (and any extraneous trailing slash) rewrite ^/mui/?(.*)$ /$1; break; proxy_pass http://localhost:8082; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; auth_basic off; } location / { # We also rewrite the Java servlet urls to move additional, 'RESTful' path elements # to a url query parameter named '_path_suffix' # rewrite ^/(.*)$ /server?_path_suffix=$1; break; proxy_pass http://localhost:8081; proxy_redirect off; } }
几乎完美。下一步将是使它要求对
/mui
中除页面/mui/river
之外的所有内容进行身份验证。
这是我的问题所在,我尝试了以下操作,当我到达/mui/river
时,它仍需要身份验证...
server { listen 8080; # http auth_basic "Restricted Area"; auth_basic_user_file /etc/ngnix/.htpasswd; location = /mui/river { rewrite ^/mui/?(.*)$ /$1; break; proxy_pass http://localhost:8082; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; auth_basic off; } # Forward requests to our node app at port 8082 # location /mui { # Remove the '/mui' portion of the path (and any extraneous trailing slash) rewrite ^/mui/?(.*)$ /$1; break; proxy_pass http://localhost:8082; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location / { # We also rewrite the Java servlet urls to move additional, 'RESTful' path elements # to a url query parameter named '_path_suffix' # rewrite ^/(.*)$ /server?_path_suffix=$1; break; proxy_pass http://localhost:8081; proxy_redirect off; } }
我如何仅打开
/mui/river
的访问权限?
这是我在这里使用的原始nginx配置,可以正常工作:服务器{监听8080; #http#将请求转发到端口8082上的节点应用程序#location / mui {#删除...
现在,您的基本身份验证是在服务器级别(在server {...}
块内部)设置的,因此它将应用于all