I've been following this tutorial, and everything seems to run OK, except for my nginx setup. My node.js
application runs on port 1337, varnish runs on port 80, stunnel on 443 and nginx on 8080.
I can reach my app correctly when i specify the port https://example.com:1337
but all I get when visiting https://example.com
is a 502 Bad Gateway
error.
This is the output of my nginx log:
2012/08/25 14:13:59 [error] 6049#0: *1 no live upstreams while connecting to upstream, client: 127.0.0.1, server: example.com, request: "GET / HTTP/1.1", upstream: "http://app_example/", host: "example.com"
2012/08/25 14:14:02 [error] 6049#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: example.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:1337/", host: "example.com"
and this is my nginx config file for that domain:
upstream example.com {
server 127.0.0.1:1337;
}
server {
server_name example.com;
listen 8080;
location / {
proxy_pass http://example.com;
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;
}
}
I'm running:
- Ubuntu 12.04
- nginx/1.1.19
- stunnel 4.42
- varnish-3.0.2
Best Answer
So first thing.. that link said they are only using nginx for static files and html files for the website. You are trying to proxy nodejs/websockets over nginx.
So why does that website say not to do that? Mainly because websockets are not supported in nginx in a stable release.
Websockets are a 1.1 spec and nginx is only 1.0 spec. Now that said.. you can compile in like tcp_proxy for nginx but just proxy it with varnish like that url pointed out. It does not make a lot of sense to go
varnish->nginx->node
just do
varnish -> node