What am I doing

  • Two NodeJS/HTTP servers running on ports 3000 and 3001
  • Using Nginx to proxy requests
    • app.localhost -> localhost:3001
    • api.app.localhost -> localhost:3000

What's wrong

Requests perfectly work on browser (Chrome) and return proper status code and JSON data, but fail request fails using curl or Postman

Connection is always refused.

curl http://api.app.localhost/languages
curl: (7) Failed to connect to api.codebottle.localhost port 80: Connection refused


Nginx config

server {
    server_name     app.localhost;

    location / {
        proxy_pass       http://localhost:3001;
        proxy_set_header                Host codebottle.localhost;
        proxy_pass_request_headers      on;

server {
    server_name     api.app.localhost;


#<ip-address>   <hostname.domain.org>   <hostname>       app.localhost.dev       api.app.localhost.dev

What I have tried

  • Using --ipv4 with curl
  • Making sure that servers, as well as Nginx, are running properly
  • Tried setting different headers like Host, Origin, and User-Agent
  • I wonder if you can bind to with multiple servers - not sure, never tried. Given you've set up domains in host suggest you try binding to domain names. "listen 80; server_name www.example.com;" – Tim Dec 18 '17 at 19:29
  • 1
    The names you have in /etc/hosts do not match the names you are trying to use in your web requests. – Michael Hampton Dec 18 '17 at 20:30
  • Please show output of curl -v http://api.app.localhost/languages. – Tero Kilkanen Dec 18 '17 at 22:22
  • @MichaelHampton I don't understand how I even managed to miss the .dev. If you can please add an answer so I can mark it as a solution – OverCoder Dec 19 '17 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.