Reputation: 4915
I've spent so much time trying to get this work that it's cutting into actual development time. I'm trying to set up two domains on my site example.com
and example2.com
but navigating to the domain in browser results in a 502 at best.
The etc/nginx/nginx.conf
that I got from a friend:
user root;
worker_processes 4;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/sites-enabled/*;
}
The etc/nginx/sites-available/sites
that I also got from a friend:
server {
server_name example.com;
# proxy pass to nodejs
location / {
proxy_pass http://127.0.0.1:9001/;
}
}
server {
server_name example2.com;
# proxy pass to nodejs
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
I've been working in circles and have tried so many different configurations that all fail, this specific one results in a Gateway error 502 for both sites.
I've never been able to get this to work and I have no idea why, A second set of eyes would be very helpful.
Upvotes: 0
Views: 286
Reputation: 151370
There is nothing that looks wrong in your nginx configuration. If the Node server to which nginx is trying to forward a connection is not actually listening on the port you specify in your configuration you will get a 502 status code.
To verify whether it is listening correctly, you can use any tool that can connect to a port to perform an HTTP GET. So, for instance:
$ curl http://127.0.0.1:9001/
Or wget
could also be used for this. If the connection is refused chances are that your node server is not running at all or configured to listen on a different port.
Upvotes: 1