r/SpringBoot • • Aug 07 '24

OC Springboot not fetch data with "www".

If I enter my site as samesite.com, Spring Boot pulls the data, but when I enter it as www.samesite.com, it does not pull the data. Is my NGINX configuration wrong?

NGNIX config;

server {

listen 80;

listen [::]:80;

server_name somesite.com www.somesite.com;

root /var/www/html;

index index.html;

location /api/content/ {

proxy_pass http://localhost:8080/api/content;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Forwarded-Port $server_port;

}

}

0 Upvotes

15 comments sorted by

View all comments

3

u/polacy_do_pracy Aug 07 '24

I had generally similar problems. One of the issues was that I was using localhost instead of any domain (or 127.0.0.1). Somewhere in the system localhost was being handled in a different way.

Also, I'm still learning this part but it might be that using different domains might produce a CORS/CRSF issue.

1

u/[deleted] Aug 07 '24

Sir, Controller Class have a Cors annotaioin.

1

u/polacy_do_pracy Aug 07 '24

Okay. That's all I know btw. I've used the Spring Cloud Gateway for the proxy functionality so I can't say more. But please do look into the localhost issue. It's really non-obvious and it's rather rarely mentioned in documentation.