【问题标题】:Angular deployed on apache2 with ssl call spring boot api on 8080 portAngular 部署在 apache2 上,在 8080 端口上使用 ssl 调用 spring boot api
【发布时间】:2020-07-05 09:30:41
【问题描述】:

我使用 Angular 创建了一个小型应用程序,并使用 Spring Boot 创建了一个 API,其中包含一个嵌入式 tomcat 服务器。

我正在尝试通过使用 let's encrypt 配置 ssl 证书来将它们部署在单个树莓派上。

我安装了 apache 2,为 angular 部分创建了一个虚拟主机,使用 certbot 创建并安装了一个 ssl 证书。那里一切都很好。 APi 部分在 .jar 中编译,当 pi 从命令行启动时我会启动它。板载 tomcat 服务器监听 8080 端口。

我启用的配置:

<IfModule mod_ssl.c>
<VirtualHost *:443>

        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName website.me

        ServerAdmin mail@gmail.com
        DocumentRoot /var/www/html/website

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf


        SSLCertificateFile /etc/letsencrypt/live/website.me/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/website.me/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf

        RewriteEngine On
        # If an existing asset or directory is requested go to it as it is
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
        RewriteRule ^ - [L]

        RewriteCond %{REQUEST_URI} ^/rest/.*$
        RewriteRule ^/rest/(.*) http://website.me:8080/rest/$1 [L]
        # If the requested resource doesn't exist, use index.html
        RewriteRule ^ /index.html


</VirtualHost>
</IfModule>

proxy.conf:

<IfModule mod_proxy.c>

        LogLevel proxy:trace5
        ProxyPreserveHost on
        ProxyRequests Off

        #RequestHeader set X-Forwarded-Proto https
        #RequestHeader set X-Forwarded-Port 443
        #RequestHeader set Access-Control-Allow-Origin "https://website.me"

        ProxyPassMatch .+\.html$ !
        ProxyPassMatch .+\.js$ !
        ProxyPass ^/rest/(.*)$ http://127.0.0.1:8080/rest/$1

        ProxyPassReverse ^/rest/(.*)$ http://127.0.0.1:8080/rest/$1

</IfModule>

apache2 的维度配置,我将监听端口 80 重定向到 443,并将 /rest/* 中发生的所有事情重定向到端口 8080。而且它必然不起作用。 跨域安全错误。

我尝试在 apache2 中配置代理并使跨源成为可能,但没有成功...

我不知道该怎么办...有什么想法吗?

【问题讨论】:

  • 浏览器在 devtools 控制台中记录的确切错误消息是什么?
  • 在 chrose 消息是:Mixed Content: The page at 'https://website.me/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://website.me:8080/rest/settings'. This request has been blocked; the content must be served over HTTPS.
  • 您需要在前端代码中使用https://website.me:8080/rest/settings作为请求URL(即https,而不是http)。
  • 好的,所以我必须从嵌入在 spring boot jar 中的 tomcat 设置 https 吗?也许在 8443 端口上?
  • 我按照本教程进行操作:baeldung.com/spring-boot-https-self-signed-certificate,现在我在 chrome 中遇到了他的错误:GET https://website.me:8080/rest/settings net::ERR_CERT_AUTHORITY_INVALID 我将尝试找出如何从 certbot 生成证书以不使用自签名证书

标签: angular spring-boot apache2 cross-domain mixed-content


【解决方案1】:

您应该改为在 Spring 中启用 COR。示例如下:https://www.baeldung.com/spring-cors

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    • 2018-08-29
    • 1970-01-01
    相关资源
    最近更新 更多