GVKun编程网logo

Spring Boot将HTTP重定向到HTTPS(springboot重定向到url)

13

本文将带您了解关于SpringBoot将HTTP重定向到HTTPS的新内容,同时我们还将为您解释springboot重定向到url的相关知识,另外,我们还将为您提供关于Apache将HTTP重定向到H

本文将带您了解关于Spring Boot将HTTP重定向到HTTPS的新内容,同时我们还将为您解释springboot重定向到url的相关知识,另外,我们还将为您提供关于Apache将HTTP重定向到HTTPS、AppEngine Node.js未将HTTP重定向到HTTPS、asp.net-mvc-4 – Azure云服务将http重定向到https无效(在许多链接上尝试过答案)、ASP.NET站点.将整个域从http重定向到https的实用信息。

本文目录一览:

Spring Boot将HTTP重定向到HTTPS(springboot重定向到url)

Spring Boot将HTTP重定向到HTTPS(springboot重定向到url)

对于基于Spring Boot的应用程序,我在application.properties上配置了ssl属性,请在此处查看我的配置:

server.port=8443server.ssl.key-alias=tomcatserver.ssl.key-password=123456server.ssl.key-store=classpath:key.p12server.ssl.key-store-provider=SunJSSEserver.ssl.key-store-type=pkcs12

我在Application.class上添加了连接,例如

@Beanpublic EmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {    final TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();    factory.addAdditionalTomcatConnectors(this.createConnection());    return factory;}private Connector createConnection() {    final String protocol = "org.apache.coyote.http11.Http11NioProtocol";    final Connector connector = new Connector(protocol);    connector.setScheme("http");    connector.setPort(9090);    connector.setRedirectPort(8443);    return connector;}

但是当我尝试以下方法时

http://127.0.0.1:9090/

重定向到

https://127.0.0.1:8443/

不执行。谁遇到过类似的问题?

答案1

小编典典

为了使Tomcat执行重定向,您需要使用一个或多个安全约束对其进行配置。您可以通过Context使用TomcatEmbeddedServletContainerFactory子类对进行后期处理来实现。

例如:

TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {    @Override    protected void postProcessContext(Context context) {        SecurityConstraint securityConstraint = new SecurityConstraint();        securityConstraint.setUserConstraint("CONFIDENTIAL");        SecurityCollection collection = new SecurityCollection();        collection.addPattern("/*");        securityConstraint.addCollection(collection);        context.addConstraint(securityConstraint);    }};

由于CONFIDENTIAL/*,这将导致Tomcat将每个请求重定向到HTTPS。如果需要对什么是重定向和不重定向进行更多控制,则可以配置多个模式和多个约束。

Apache将HTTP重定向到HTTPS

Apache将HTTP重定向到HTTPS

apache中强制将http重定向到https ,许多站点只需要始终使用ssl运行。我们需要确保每个用户都必须通过ssl访问网站。如果任何用户尝试使用非ssl url访问该网站,则他必须是重定向到ssl网站的。

Apache将HTTP重定向到HTTPS

本篇文章将介绍关于在每次使用apache mod_rewrite模块时将网站重定向到ssl url。

选择1:

在apache配置文件中编辑virtualhost网站并添加以下选项。将www.example.com更改为你的实际域名。

Redirect permanent / https://www.example.com/
登录后复制

选择2:

在Apache配置文件中编辑VirtualHost网站并添加以下设置。你也可以在网站的文档根目录下的.htaccess文件中添加相同的设置。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
登录后复制

如果要将特定URL重定向到https。使用以下设置。例如,如果有人试图访问网站上的always-secure.html文件。用户必须使用SSL访问URL。

 RewriteEngine On
 RewriteRule ^always-secure.html$ https://www.example.com/always-secure.html [R=301,L]
登录后复制

本篇文章到这里就已经全部结束了,更多其他精彩内容大家可以关注PHP中文网的Linux视频教程栏目!!!

以上就是Apache将HTTP重定向到HTTPS的详细内容,更多请关注php中文网其它相关文章!

AppEngine Node.js未将HTTP重定向到HTTPS

AppEngine Node.js未将HTTP重定向到HTTPS

您需要为每个handler that this behavior添加secure: always。请注意,您有两个具有相同- url: /.*的处理程序。该网址的最后一个定义没有secure参数。

asp.net-mvc-4 – Azure云服务将http重定向到https无效(在许多链接上尝试过答案)

asp.net-mvc-4 – Azure云服务将http重定向到https无效(在许多链接上尝试过答案)

我正在尝试执行从http到https重定向/重写流量的“简单”任务,我在CloudService中有一个端点,该端点已正确配置为SSL.

我尝试了很多IIS重写规则,如下所示,但没有一个正在运行.我也尝试直接在IIS 8服务器上通过远程桌面设置规则,这也是行不通的.

当我在Azure web.config文件中输入任何标记时,重写标记下面有一条蓝线,并在< system.webServer>下显示一条消息说它无效. :

<system.webServer>
...
      <rewrite>
          <rules>
              <rule name="RedirectToHTTPS" stopProcessing="true">
                  <match url="(.*)" />
                  <conditions>
                      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                  </conditions>
                  <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
              </rule>
          </rules>
      </rewrite>

  </system.webServer>

任何建议都非常感谢.

解决方法

为了使这些规则有效,您必须配置两个端点 – HTTP和HTTPS!

如果您尚未在端口80上配置纯HTTP端点,则您的服务器将永远不会受到Internet流量的影响,因此重写规则将永远不会触发.因此,当您尝试通过纯HTTP打开域时,您将获得超时.当您没有为端口定义端点时,根本没有进程侦听端口80.

ASP.NET站点.将整个域从http重定向到https

ASP.NET站点.将整个域从http重定向到https

就像在标题中一样.如何重定向整个域,例如:http://testdomain.com.au/到https://testdomain.com.au/我可以在IIRF文件中执行此操作吗?如果是,这应该是什么样子?如何将IIRF文件绑定到站点?

解决方法

您可以通过IIS Rewrite模块执行此操作:

http://www.iis.net/downloads/microsoft/url-rewrite

http://www.iis-aid.com/articles/how_to_guides/redirect_http_to_https_iis_7

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
   <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>

或者您可以通过Global.asax文件重定向:

protected void Application_BeginRequest(Object sender,EventArgs e)
{
    if ( !Request.IsSecureConnection)
    {
            string path = string.Format("https{0}",Request.Url.AbsoluteUri.Substring(4)); 

            Response.Redirect(path);
    }
}

http://forums.asp.net/t/1340392.aspx

关于Spring Boot将HTTP重定向到HTTPSspringboot重定向到url的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Apache将HTTP重定向到HTTPS、AppEngine Node.js未将HTTP重定向到HTTPS、asp.net-mvc-4 – Azure云服务将http重定向到https无效(在许多链接上尝试过答案)、ASP.NET站点.将整个域从http重定向到https等相关内容,可以在本站寻找。

本文标签: