I am trying to access a Spring Backend from an Angular Frontend using https. I also use Keycloak for authentication. I made a simple Angular app that, after proper authentication, shows a button that should call an endpoint on the backend and log "hello" on the console, but I keep getting ERR_CONNECTION_REFUSED
.
All the components are hosted on an AWS Linux machine and I use the browser on my local Windows machine to access the frontend. Each component has a hostname, thus I had to modify the etc/hosts
file on the AWS machine to map the hostnames to the localhost IP 127.0.0.1
, and the hosts
file on the Windows machine to resolve each hostname to the AWS machine's public IP.
The frontend is served through Nginx and this is the nginx.conf (non relevant parts are omitted):
http { ssl_certificate /root/certs/MyCertificate.crt; ssl_certificate_key /root/certs/MyKey.key; ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH; ssl_protocols TLSv1.1 TLSv1.2; ... server { listen 443 ssl default_server; listen [::]:443 ssl default_server; server_name my.angular.test; root /var/srv/mysite; location / { try_files $uri $uri/ /index.html; } }...}
This is the application.properties of the backend:
spring.application.name=deploy-demospring.security.oauth2.resourceserver.jwt.issuer-uri=https://my.test.keycloak.com:8443/realms/testjwt.auth.converter.resource-id = test-clientjwt.auth.converter.principal-attribute = preferred_usernameserver.ssl.key-store-type=PKCS12server.ssl.key-store=classpath:keystore/keystore.p12server.ssl.key-store-password=xxxxxserver.ssl.key-alias=keystore-aliasserver.ssl.enabled=truetrust.store=classpath:keystore/keystore.p12trust.store.password=xxxxxserver.port = 8081server.address = my.spring.test
I first thought that the problem was due to the CORS/CSRF protection provided by Spring as a default, so I disabled both in the configuration file, but I still got the error.
I also double checked all of the trusted keystores configured for Angular, Spring and Keycloak, thinking that the problem was due to untrusted certificates, but still no luck.
Finally, port 8081 (the one used by Spring backend) is open for ingoing traffic in my security group. For security reasons, I've opened the port only for my local IP, but I also made an attempt by allowing for all IPs. Still no luck.