首页 > 解决方案 > heroku 本地网络 - 重定向到 https://localhost,但失败

问题描述

我在让我的 Spring 应用程序在本地部署 user 时遇到了一些麻烦heroku local web。它在测功机上运行良好。

这是我的 Procfile 中的内容:

web: java $JAVA_OPTS -jar web/target/dependency/webapp-runner.jar --expand-war --enable-compression --port $PORT web/target/*.war

代码中的任何地方都没有提到 WebSecurityConfig 和 WebSecurityConfigurerAdapter。

看起来它在本地部署得很好:

MacBook-Pro:motherbrain brianstinar$ heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
4:40:47 PM web.1 |  Expanding gwd-web-1.4.3.war into /Users/brianstinar/Noventum/GeeksWhoDrink/motherbrain/target/tomcat.5000/webapps/expanded
4:40:47 PM web.1 |  Adding Context  for /Users/brianstinar/Noventum/GeeksWhoDrink/motherbrain/target/tomcat.5000/webapps/expanded
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.coyote.AbstractProtocol init
4:40:48 PM web.1 |  INFO: Initializing ProtocolHandler ["http-nio-5000"]
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
4:40:48 PM web.1 |  INFO: Using a shared selector for servlet write/read
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.catalina.core.StandardService startInternal
4:40:48 PM web.1 |  INFO: Starting service Tomcat
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.catalina.core.StandardEngine startInternal
4:40:48 PM web.1 |  INFO: Starting Servlet Engine: Apache Tomcat/8.0.47
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.catalina.loader.WebappLoader buildClassPath
4:40:48 PM web.1 |  INFO: Unknown loader jdk.internal.loader.ClassLoaders$AppClassLoader@55054057 class jdk.internal.loader.ClassLoaders$AppClassLoader
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
4:40:48 PM web.1 |  INFO: No global web.xml found
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.jasper.servlet.TldScanner scanJars
4:40:48 PM web.1 |  INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
4:40:48 PM web.1 |  Dec 15, 2020 4:40:48 PM org.apache.catalina.core.ApplicationContext log
4:40:48 PM web.1 |  INFO: Initializing Spring root WebApplicationContext
4:40:55 PM web.1 |  WARNING: An illegal reflective access operation has occurred
4:40:55 PM web.1 |  WARNING: Illegal reflective access by org.springframework.util.ReflectionUtils (file:/Users/brianstinar/Noventum/GeeksWhoDrink/motherbrain/target/tomcat.5000/webapps/expanded/WEB-INF/lib/spring-core-5.1.6.RELEASE.jar) to constructor java.math.BigInteger(long)
4:40:55 PM web.1 |  WARNING: Please consider reporting this to the maintainers of org.springframework.util.ReflectionUtils
4:40:55 PM web.1 |  WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
4:40:55 PM web.1 |  WARNING: All illegal access operations will be denied in a future release
4:41:32 PM web.1 |  Dec 15, 2020 4:41:32 PM org.apache.coyote.AbstractProtocol start
4:41:32 PM web.1 |  INFO: Starting ProtocolHandler ["http-nio-5000"]

但是如果我去 http://localhost:5000/ 我会得到一个 302 到 https://localhost 和一个 Set-Cookie: Set-Cookie: JSESSIONID=E97001499B33CE33B29FB1D53A14DBFB; Path=/; HttpOnly

我试过设置

server.session.cookie.secure=false
secure.cookie=false
server.servlet.session.cookie.secure=false

在我的 version.properties 中,这似乎没有帮助。

我还补充说:

    <!-- didn't work
    <server>
        <session>
            <cookie>
                <secure>false</secure>
            </cookie>
        </session>
    </server>
    -->
    <server> <!-- also didn't work -->
        <serverlet>
            <session>
                <cookie>
                    <secure>false</secure>
                </cookie>
            </session>
        </serverlet>
    </server>

到我的 web/src/main/webapp/WEB-INF/web.xml。

所以,我不确定发生了什么。我想我不明白如何正确设置这个指令。我在使用 Tomcat 运行它方面取得了一些进展,但是由于我继承了这个项目,mvn 对于实际的 heroku 部署来说是最正确/更新的。我想让它在本地进行以实现更快的开发,并且我宁愿不在 Tomcat 内处理 443 和 80 的自签名 SSL,但现在这是我能看到进展的唯一途径。

我还尝试使用 Tomcat 7 maven 插件运行它,如下所示:

mvn -X org.apache.tomcat.maven:tomcat7-maven-plugin:2.0:run -Dtomcat.ignorePackaging=true

有同样的错误。

现在我正在设置 Tomcat 7,并实际安装 SSL 证书以通过 https:// 在 443 上本地运行它。运行 Tomcat 的这些便利实际上似乎都不是很方便。

标签: springheroku-cli

解决方案


我安装了一个蛇油 SSL 证书,在没有任何便利的情况下运行 Tomcat(没有 maven 插件,没有 heroku 本地插件......)此外,我的应用程序并非设计为在子目录中运行,这主要是搞砸了静态资源托管被硬编码到 Web 根目录。

因此,我的应用程序具有需要 SSL 的依赖项(特别是 jSessionid),以及其他降低灵活性的架构决策。


推荐阅读