我目前有一个将代理传递到后端服务器的Nginx虚拟主机。如果它收到来自后端服务器的401响应,则它将重定向到/login
位置。这个/login
位置将代理传递给我可以登录的任何身份服务器。
我正在尝试在apache虚拟主机中镜像此功能,但似乎无法满足我的需要。据我所知,处理来自后端服务器的401响应的唯一方法是重定向到本地页面或远程URL(即htdocs/errors/401.html
或http://127.0.0.1/errors/401.html
)。
这在Apache内可行吗?我觉得自己在俯视某些事情。
我在nginx frontend.conf中拥有什么:
server {
listen 80;
server_name 127.0.0.1;
location /login {
proxy_pass http://{{ identity_provider }};
}
location / {
proxy_pass http://{{ backend_server }};
proxy_intercept_errors on;
error_page 401 /login;
}
}
我在Apache frontend.conf中拥有什么:
<VirtualHost *:80>
ServerName 127.0.0.1
ServerAdmin webmaster@localhost
DocumentRoot htdocs/
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /error/ !
ErrorDocument 401 /error/401.html
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass "/" "http://{{ backend_server }}"
ProxyPassReverse "/" "http://{{ backend_server }}"
<Location />
Order allow,deny
Allow from all
ProxyErrorOverride On
</Location>
<Location /login>
ProxyPass "http://{{ identity_provider }}"
</Location>
</VirtualHost>
401.html
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; url=http://127.0.0.1/login">
<script type="text/javascript">
window.location.href = "http://127.0.0.1/login"
</script>
<title>Page Redirection</title>
</head>
<body>
<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
If you are not redirected automatically, follow this <a href='http://127.0.0.1/login'>link to example</a>.
</body>
</html>