在8080端口上通过ssl调用spring boot api在apache2上部署的角

问题描述 投票:0回答:1

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

我正在尝试通过加密配置ssl证书,将它们部署在单个树莓派上。

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

我启用的conf:

<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 [email protected]
        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中的交叉源成为可能,但没有成功...

我不知道该怎么办...知道吗?

angular spring-boot cors apache2 cross-domain
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.