Run spring boot website without adding HTTP or HTTPS - spring

I am working with spring boot microservice application and gateway generated using jhipster. I have hosted my site on AWS EC2 instance.
Site Url: http://192.167.1.17:8082
I have redirected the port to 443 to run on https.
Let's say my site is :
http://192.167.1.17 OR http://mytestsite.com
Now the requirement is that if I type in the browser - 192.167.1.17 OR mytestsite.com
It should automatically redirect to :
http://192.167.1.17 OR http://mytestsite.com
Spring boot application has embedded tomcat. How can I do this HTTP or HTTPS redirect automatically with the hosted site on AWS EC2 instance?

Related

Could not receive HTTPS in Spring Boot App when It deployed on Azure

I deployed a Spring boot app on Azure and config Authentication.
After deployed success, I clicked in to App Service URL (HTTPs) and and executed some authorization steps and do more.
However, When I checked URL in HttpServletRequest. It is HTTP not HTTPs.
Does I need config more TLS/SSL in Azure App Service and source code ?

spring boot actuator works in local but not in production (aws)

Spring boot actuator works fine on my local and I can access it in browser
http://localhost:8000/actuator
I can access my system in production as follows
https://somedomain.com/#/overview
But I cannot access the actuator when the system is deployed in AWS, when accessed as follows
https://somedomain.com:8000/actuator
In AWS EC2 console, I notice that port 8000 is enabled as custom TCP for inbound rules

Spring boot API endpoint does not work after setting the DNS record

I have a spring boot web service running on localhost:8000 with an embedded Apache Tomcat.
Frontend is developed using Angular and is running on nginx and port 80. Connection between front- and back-end is established with a REST API endpoint, i.e. /v1/getdata/...
We have a static IP and outside access is OK with this configuration. But after setting a DNS record, i.e. https://x.y.com for the static IP, the spring web server does not return data and ERR_TUNNEL_CONNECTION_FAILED error is occurred in Angular, although the front-end is loaded successfully on port 80.
The only server-side configurations in Spring app is server.port=8000 and CORS configs.
I have set [STATIC-IP]:8000 and https://x.y.com:8000 for the api address in Angular but neither worked. However accessing with static IP is still working.
I think there is a problem with SSL configuration.
Any Ideas?

How to point spring boot java app to subdomain?

i'm very new to AWS and currently having issues with domain and subdomain for my app.
I'm trying to host my Java Spring Boot web application as REST API and Angular app as front end on AWS EC2 instance. I want my Angular to run on port and be accessible via example.com and my java app to be accessible via api.example.com.
I've connected domain from godaddy to my Elastic IP already, and created Hosted zone in Route 53 for subdomain and added nameservers to domain on godaddy. Currently i'm waiting for propagation, and I assume that once I run angular on port :80, it will be accessible via example.com.
But how to point java app to api.example.com ?
As spring boot is using embedded tomcat, where should I set up a link between port and subdomain?
Thank you for your help.

Spring Boot & ELB - How do I make the load balancer redirect http to https?

I have deployed a Spring Boot application via Elastic Beanstalk. I'm using a load balancer, so this is the flow (as far as I understand):
Internet/Browser request ---HTTPS---> Load Balancer ---HTTP---> Spring Boot App Server
So essentially, the SSL terminates at the load balancer and the app server just deals with plain old HTTP.
But in the case of a HTTP request from the browser, I would like the load balancer to automatically redirect to HTTPS.
There are several questions about this issue:
Spring Boot with Embedded Tomcat behind AWS ELB - HTTPS redirect
How to redirect automatically to https with Spring Boot
Spring Boot redirect HTTP to HTTPS
But none of the answers to these questions make sense to me. Perhaps I'm misunderstanding, but all the answers basically make the Spring Boot app only server HTTPS request (for example when using http.requiresChannel().anyRequest().requiresSecure()).
However, this goes against the flow because I'm perfectly fine with the SSL terminating at the load balancer and the Spring Boot app server just dealing with HTTP. So if I require SSL at the spring boot level, then I'll need to do an end-to-end SSL connection, which isn't really required for my application.
I have also used the following properties, which don't seem to help either:
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
With the help of this article, I was finally able to figure out how to do this for a Spring Boot app in an ELB environment.
I had to create a conf file in src/main/webapp/.ebextensions/nginx/conf.d. I just called it myconf.conf.
In myconf.conf, I put this code in:
server {
listen 80;
server_name www.my-site.com;
if ($http_x_forwarded_proto != "https") {
rewrite ^(.*)$ https://$server_name$REQUEST_URI permanent;
}
}
Also, make sure that both HTTP and HTTPS listeners are open for the load balancer.
Additionally, my spring boot app only opens up HTTP since the load balancer already terminates SSL.
AWS Load balancer cannot handle redirection. You may do it via your server or by using cloudfront distributions.

Resources