I have an application developed by angular as frontend and spring boot for the backend.
I deployed them in Nginx running in Ubuntu server including let's encrypt ssl certificates
The front end is deployed in the following path /var/www/my-app-domain.local
The backend is a jar which is running on port 8080
The Nginx configuration is in following file located in /etc/nginx/conf.d/my-app-domain.local.conf
server {
listen 80;
listen [::]:80;
server_name my-app-domain;
location /api/ {
proxy_pass http://localhost:8080/;
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;
}
}
server {
server_name my-app-domain www.my-app-domain; # managed by Certbot
index index.html;
root /var/www/my-app-domain.local;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.html;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/my-app-domain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my-app-domain/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}server {
if ($host = my-app-domain) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = my-app-domain) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
server_name my-app-domain www.my-app-domain;
return 404; # managed by Certbot
}
When I call the domain name in the browser, it rejected the call for the API from the webapp showing this error in the console : Failed to load resource: net::ERR_CONNECTION_REFUSED for calling http://localhost:8080/api/*****
However, when I call the same API from the browser, it's calling successfully without any issues.
Is my Ngnix configuration incorrect? what should I do with this error and what is the proper way for calling APIs in production environment?