-1

I created a small application with Angular and an API with Spring Boot, containing an embedded tomcat server.

I am trying to deploy them on a single raspberry pi, by configuring an ssl certificate with let's encrypt.

I installed apache 2, created a virtual host for the angular part, created and installed an ssl certificate with certbot. There everything is fine. The APi part is compiled in .jar, and I launch it when the pi starts from the command line. The onboard tomcat server listens on port 8080.

My enabled 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 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>

Dimensioned configuration of apache2, I have a redirection of listening on port 80 to 443 and a redirection for everything that happens in / rest / * to port 8080. And there necessarily it does not work. Cross origin security error.

I tried to configure a proxy and make cross origin possible in apache2 without success ...

I don't know what to do... any idea ?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
DarkChyper
  • 25
  • 1
  • 8
  • What are the exact error messages that the browser is logging in the devtools console? – sideshowbarker Mar 24 '20 at 22:29
  • in chrose the message is : `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.` – DarkChyper Mar 25 '20 at 08:24
  • 1
    You need to use `https://website.me:8080/rest/settings` as the request URL in your frontend code (that is, `https`, not `http`). – sideshowbarker Mar 25 '20 at 08:36
  • ok so i have to set the https from the tomcat embended in the spring boot jar ? maybe on the 8443 port ? – DarkChyper Mar 25 '20 at 08:54
  • i follow this tutorial : https://www.baeldung.com/spring-boot-https-self-signed-certificate and now i got his error in chrome : `GET https://website.me:8080/rest/settings net::ERR_CERT_AUTHORITY_INVALID` I'll try to find how generate a certification from certbot to not use self signed certificate – DarkChyper Mar 25 '20 at 09:50

1 Answers1

-1

You should enable CORs in Spring instead. Here is the example: https://www.baeldung.com/spring-cors