我正在尝试使用nginx进行重定向.想法是将uri/id_1234 /重定向到localhost:1234以用于某些端口.固定端口的重定向:
location /id_1234/ {
rewrite ^/id_1234/(.*) /$1 break;
proxy_pass http://localhost:1234;
proxy_redirect http://localhost:1234/ $scheme://$host/id_1234/;
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好.现在我尝试将1234更改为任何端口:
location ~* ^/id_([0-9]*)/ {
rewrite ^/id_([0-9]*)/(.*)$ /$2 break;
proxy_pass http://localhost:$1;
proxy_redirect http://localhost:$1/ $scheme://$host/id_$1/;
}
Run Code Online (Sandbox Code Playgroud)
使用此配置,我收到502错误,日志中出现以下错误:
no resolver defined to resolve localhost
Run Code Online (Sandbox Code Playgroud)
如果我在localhost:之后将$ 1更改为实际端口,则它适用于指定的端口.如何使用正则表达式指定重定向端口?
提前致谢!
我正在尝试以下列方式配置nginx.我有几个服务正在运行,并希望通过设置不同的nginx位置来访问它们.我还想使用PAM管理用户身份验证,并允许用户根据他们的组访问位置.所以我创建了以下配置:
server {
listen 80;
location /service1/ {
auth_pam "Accessing service1";
auth_pam_service_name "service1";
rewrite ^/service1/(.*)$ /$1 break;
proxy_pass http://localhost:1234;
proxy_redirect http://localhost:1234/ $scheme://$host/service1/;
}
location /service2/ {
auth_pam "Accessing service2";
auth_pam_service_name "service2";
rewrite ^/service2/(.*)$ /$1 break;
proxy_pass http://localhost:5678;
proxy_redirect http://localhost:5678/ $scheme://$host/service2/;
}
}
Run Code Online (Sandbox Code Playgroud)
我还创建了以下文件,其中包含以下内容:
/etc/pam.d/service1:
auth required pam_listfile.so onerr=fail item=group sense=allow file=/etc/service1.group.allow
@include common-auth
Run Code Online (Sandbox Code Playgroud)
/etc/pam.d/service2:
auth required pam_listfile.so onerr=fail item=group sense=allow file=/etc/service2.group.allow
@include common-auth
Run Code Online (Sandbox Code Playgroud)
/etc/service1.group.allow:
service1-group
Run Code Online (Sandbox Code Playgroud)
/etc/service2.group.allow:
service2-group
Run Code Online (Sandbox Code Playgroud)
一切正常,只有来自service1-group的用户才能访问/ service1 /,只有来自service2-group的用户才能访问/ service2 /.现在考虑user1是service1-group和service2-group的成员.我尝试访问/ service1 /,输入user1和他的密码,成功访问/ service1 /.现在我导航到/ service2 /,我需要再次登录,再次作为user1.是否有可能以某种方式保存我授权的用户并仅在该用户无权访问该位置时显示登录窗口.即,如果user1是service1-group和service2-group的成员,我可以访问/ service1 /,在此登录,然后在没有新登录的情况下导航到/ …