spring - Apache + SpringBoot + SSL

标签 spring apache ssl https

我正在尝试使用 SSL 证书在 apache2 上配置我的 spring boot 应用程序,但在将其投入生产之前,我无法理解我正在执行的所有步骤是否正确。我需要使用 https 并将所有调用从 80 重定向到 443

因此,我的 jar 应用程序部署在端口 8080 上,所以我首先以这种方式编辑了我的 /etc/apache2/sites_available/000-default.conf

<VirtualHost *:80>
       ServerName www.example.com

        ServerAdmin webmaster@localhost


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ProxyPreserveHost On
        ProxyPass / http://localhost:8080/

</VirtualHost>

当我只需要普通的 http 时,这非常有效

现在我有一个 CA 证书,我将 crt 和 key 放在 /etc/apache2/ssl/certs//etc/apache2/ssl/private/ 并编辑了

default-ssl.conf

这样

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost

                DocumentRoot /var/www/html


                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined


                SSLEngine on
                SSLCertificateFile      /etc/ssl/certs/xxxxxxxxxxxx.crt
                SSLCertificateKeyFile /etc/ssl/private/yyyyyyyyyyy.key
                SSLCertificateChainFile /etc/apache2/ssl/certs/sf_bundle-g2-g1.crt

     <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>
    </VirtualHost>
</IfModule>

这样一来,我应该已经在 Apache 上启用了 SSL,对吧? 现在我需要了解如何将所有调用从 80 重定向到 443,以及我遵循的工作流程是否正确

最佳答案

抱歉,如果我没有捕获要点,但我不确定您的问题与 Spring Boot 有何关联。

Apache“只是”一个 HTTP 服务器。 Spring 应用程序在 Tomcat 或 Wildfly 等应用程序服务器中运行,或者作为具有嵌入式 Tomcat 的独立 JAR。

我猜你想在 Spring 应用程序之前使用 Apache 作为代理,但据我所知,它在 SSL 方面的配置并没有连接到 Spring。

您的问题的一个可能答案是这样做(如此处所述:http to https apache redirection):

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName mysite.example.com
  DocumentRoot /usr/local/apache2/htdocs 
  Redirect permanent / https://mysite.example.com/
</VirtualHost>

<VirtualHost _default_:443>
  ServerName mysite.example.com
  DocumentRoot /usr/local/apache2/htdocs
  SSLEngine On
</VirtualHost>

关于spring - Apache + SpringBoot + SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44910836/

相关文章:

python - 导入错误: Could not import settings 'mysite.settings' (Is it on sys.路径?): No module named mysite.设置

ssl - 具有多个域的通配符 SSL

java - 如何使用 session 工厂关闭连接

linux - 为 WHM/cPanel 设置 CentOS 服务器的最安全、完整的过程是什么?

java - 415 当请求正文具有以自定义对象为键的 Map 时,出现不支持的对象异常

php - 无法通过 PHP 连接到 MSSQL

ssl - 如何使用 tls 证书而不是 ssl

用于静态服务的 Web 应用程序的 SSL

java - Apache Kafka 放弃了我的生产者和消费者

java - 如何修复 Spring Boot 中的 "Application failed to start"并要求定义 bean