Home > Back-end >  Apache 2 Proxy mode Spring boot and SSL
Apache 2 Proxy mode Spring boot and SSL

Time:08-28

I have a server running a Spring boot application on port 8080, I want to connect it to Android application which is built using Ionic and Cordova.

There is also a web application built using Angular 13 and is the basis for the Android app.

While connecting using HTTPS(redirect using Apache proxy mode from port 443 to port 8080), I try to log in using POST method all is well, but any GET request is blocked with error 403.

However, If I connect using HTTP only directly using port 8080 it works.

My CORS setup:

@Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source =
                new UrlBasedCorsConfigurationSource();
        var config = new CorsConfiguration();
        config.setAllowedOrigins(Arrays.asList("*"));
        config.setAllowedMethods(Arrays.asList("*"));
        config.setAllowedHeaders(Arrays.asList("*"));
        config.setAllowCredentials(false);
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }

and my host configuration in apache :

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ServerName www.someserver.som
        RewriteEngine on
        RewriteCond %{SERVER_NAME} =www.someserver.som [OR]
        RewriteCond %{SERVER_NAME} =someserver.som
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

and my proxy mode:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ServerName www.someserver.som
        Include /etc/letsencrypt/options-ssl-apache.conf
        ServerAlias softcare.sy
        SSLCertificateFile /etc/letsencrypt/live/softcare.sy/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/softcare.sy/privkey.pem
</VirtualHost>
</IfModule>

It is worth noting that when connecting through Insomnia, the connection works and data is retrieved even when connecting using SSL.

CodePudding user response:

The solution turns out to be very stupid one.

I forgot to add someserver.som to the list of allowed domains for Angular JWT.

It is now working as intended

  • Related