Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
Cannot reach localhost from angular application configured inside nginx

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?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!