By Brian Park

2011-05-19 02:57:16 8 Comments

I have a personal domain running on a VPS. I'd like to setup nginx as a reverse proxy to node.js application, but it's not working. Could anyone look at my configuration and tell me what I'm doing wrong?

Let's assume my domain name is Basically, I'd like to make it so that when I go to, it proxies to the node.js app. I also have and setup in nginx.

Here's my nginx configuration for the reverse proxy (, setup is omitted):

server {
  listen 80;

  access_log /srv/www/;
  error_log /srv/www/;

  location / {
      proxy_pass    ;
      proxy_redirect          off;
      proxy_set_header        Host            $host;
      proxy_set_header        X-Real-IP       $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      client_max_body_size    10m;
      client_body_buffer_size 128k;
      proxy_connect_timeout   90;
      proxy_send_timeout      90;
      proxy_read_timeout      90;
      proxy_buffers           32 4k;

And here's my node.js application:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(3000, "");

I restarted the nginx server and ran the node.js application. But if I go to, it says " does not exist or unavailable."

I'm not sure what's wrong with my configuration. I tried various combinations, too.

These are the configurations I have tried:

proxy_pass in nginx           |   hostname in node.js app
http:// localhost:3000/        |   ---.listen(3000, "localhost")
http://        |   ---.listen(3000, "")
http:// |   ---.listen(3000, "")

I also tried the following nginx configuration:

upstream nodeapp {

server {
   location / {
     proxy_pass     http:// nodeapp;

And it doesn't work either. What am I doing wrong? I've searched on the web for a few hours and tried various approaches but they all don't seem to work.

I'd really appreciate if someone can help me out.



@prasoon 2020-04-16 19:26:07

If you want too run your node.js app on then in proxy configuration you need to define node on or localhost:3000 and not as

If you need to run on with 3000 as port then initially you need to define nginx rule for port 80 as well. By default a domain is mapped against port 80 and 443. Rest you can change configuration in your node.js startup file.

@Maxim 2018-12-07 16:02:58

NodeJS code .listen(3000, ""); waiting for in host header so try to change proxy_set_header Host $host;

to new one

proxy_set_header        Host  ;

@Saud Alfadhli 2011-05-19 06:53:45

in nginx configuration ( proxy_pass ) you have to remove spaces in URL between (http://) and (your hostname) :

you wrote:

proxy_pass http:// nodeapp;

you have to write:

proxy_pass http://nodeapp;

I try on my server and add space after http:// .. then restart nginx but the nginx is faild! so, I think this is maybe your nginx problem! try to remove this space and I hope working with you!

Good luck!

@Brian Park 2011-05-20 15:32:59

The reason I put space in http:// nodeapp; is because Stackoverflow complained that I have too many links (possibly spam) in my question post. In my actual configuration, I had it as nodeapp; rather than http:// nodeapp.

Related Questions

Sponsored Content

4 Answered Questions

[SOLVED] Keycloak Redirect url with nginx is going to http rather than https

  • 2018-04-03 12:02:15
  • Atulya Nair
  • 2319 View
  • 5 Score
  • 4 Answer
  • Tags:   nginx jboss

12 Answered Questions

[SOLVED] Node.js + Nginx - What now?

  • 2011-02-15 20:49:02
  • Van Coding
  • 351174 View
  • 1002 Score
  • 12 Answer
  • Tags:   node.js nginx concept

19 Answered Questions

2 Answered Questions

[SOLVED] Express - req.ip returns

2 Answered Questions

1 Answered Questions

[SOLVED] nginx proxy pass Node, SSL?

1 Answered Questions

[SOLVED] nginx proxy pass with php and relative path

  • 2012-06-06 22:04:08
  • Gilles Grandguillaume
  • 2546 View
  • 0 Score
  • 1 Answer
  • Tags:   php proxy nginx

Sponsored Content