【问题标题】:HTTPS Grails application URLHTTPS Grails 应用程序 URL
【发布时间】:2014-01-03 12:01:41
【问题描述】:

我的 Grails 应用程序通过 HTTPS 和 Config.groovy 运行,我已设置:

environments {
    development {
        grails.serverURL = "https://localhost:8443/foo"
    }
}

当我执行grails run-app以开发模式启动应用程序时,控制台上打印的最后一条消息是:

服务器正在运行。浏览至http://localhost:8082/foo

如果我不小心点击了这个 URL 来访问应用程序,由于同源安全策略(因为 https://localhost:8443http://localhost:8082 是不同的主机),我会收到各种错误。

为什么当我设置了grails.serverURL = "https://localhost:8443/foo" 时,Grails 会提示我通过http://localhost:8082/foo 访问我的应用程序

更新

我把启动命令改成了grails run-app -https,现在控制台上打印的最后一条消息是:

服务器正在运行。浏览至http://localhost:8082/foohttps://localhost:8443/foo

为什么我可以选择 HTTP 或 HTTPS,而不仅仅是后者?另外,我在启动过程中遇到了这个异常:

http11.Http11Protocol Failed to initialize end point associated with ProtocolHandler ["http-bio-8443"]
java.net.BindException: Address already in use <null>:8443
    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:407)

我在运行此命令之前检查了端口 8443 是否正在使用(不是),但尽管出现此异常,服务器似乎仍在启动,因此这不是主要问题。

【问题讨论】:

    标签: grails https


    【解决方案1】:

    用下面的代码替换 grails.serverURL。

    可以使用以下system properties设置端口:

    grails.server.port = 8082
    

    这应该适用于 http 和 https。只配置一个:

    grails.server.port.https = 8082
    

    【讨论】:

    • 实际上,我正试图让它在 HTTPS 的 8443 端口上运行。我尝试删除grails.serverURL 并仅添加grails.server.port.https = 8443,但它仍然提示我通过http://localhost:8082/foo 访问它
    • 但是在 https 上运行的是什么?从上面列出的文档中: 参数:https - 在主服务器旁边启动一个 HTTPS 服务器(默认在端口 8443 上)。需要明确的是,该应用程序将可以通过 HTTPS 和 HTTP 访问。
    【解决方案2】:

    您需要使用--https 参数来运行应用程序,以便Grails 在开发模式下响应HTTPS 和HTTP。至少根据documentation

    尝试使用

    grails run-app --https
    

    此外,据我所知,grails.serverURL 通常由标记库和插件使用,而不是启动过程。

    【讨论】:

      【解决方案3】:

      您可以在 BuildConfig.groovy 中通过 https 设置您想要运行应用程序的 ssl 端口。您可以将以下内容添加到您的 BuildConfig.groovy

      //You can specify another port here to get rid of your startup exception grails.server.port.https="8443"
      grails.server.host="localhost"

      然后尝试 grails run-app -https,您应该可以在您定义的 ssl 端口或默认的 8080 端口上运行您的应用程序

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-04
        • 1970-01-01
        • 1970-01-01
        • 2012-12-24
        • 2013-10-26
        • 1970-01-01
        相关资源
        最近更新 更多