我已经制作了一个asp.net核心应用程序,我试图用反向代理在Apache中托管它 . 该应用使用Cookie身份验证:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "CookieAuthentication",
LoginPath = new PathString("/Account/Login/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
在httpd.conf中,我想使用一个只有SSL的主机和自定义端口,该端口提供来自Kestrel的内容 .
Listen 34567
<VirtualHost *:34567>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
SSLEngine on
SSLProtocol all -SSLv3
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:!RC4+RSA:+HIGH:+MEDIUM:!LOW:!RC4
SSLCertificateFile certs/server.crt
SSLCertificateKeyFile certs/server.key
</VirtualHost>
当我使用url https://testserver1:34567时,它会重定向到http://testserver1:34567/Account/Login/?ReturnUrl=%2F,这当然会给出 Bad Request . 如果我通过将其更改为https来更正网址,之后一切正常 .
我怎样才能使它始终重定向到https网址?
1 回答
我解决了我的方法是将所有http请求(包括的路由)重定向到https请求 .
这是我的整个Apache配置文件 .
关键是
VirtualHost *:80
部分,因为它是重定向请求的部分 . 另一个只是消费它们的问题 .