When I first visit the website, it loads correctly. but on refresh, it gives me the error 502 Bad Gateway Nginx/1.14.0 (Ubuntu). I am deploying a simple e-commerce site with nodejs. I am using vps which is running ubuntu-18.04-x86_64.
Below is what i get when i run error logs.
tail -f /var/log/nginx/error.log
2022/07/19 01:35:17 [error] 3810#3810: *197 no live upstreams while connecting to upstream,
client: 111.90.141.20, server: www.example.com, request: "GET /mysqladmin/ HTTP/1.1",
upstream: "http://localhost/mysqladmin/", host: "vps_ip_address", referrer:
"http://vps_ip_address/"
2022/07/19 01:35:17 [error] 3810#3810: *198 no live upstreams while connecting to upstream,
client: 111.90.141.20, server: www.example.com, request: "GET /mysql-admin/ HTTP/1.1",
upstream: "http://localhost/mysql-admin/", host: "vps_ip_address", referrer:
"http://vps_ip_address/"
2022/07/19 01:39:11 [error] 3810#3810: *204 connect() failed (111: Connection refused) while
connecting to upstream, client: 197.232.142.53, server: www.example.com, request: "GET /blog
HTTP/1.1", upstream: "http://127.0.0.1:8000/blog", host: "www.example.com", referrer:
"http://www.example.com/"
2022/07/19 01:39:11 [error] 3810#3810: *204 connect() failed (111: Connection refused) while
connecting to upstream, client: 197.232.142.53, server: www.example.com, request: "GET /blog
HTTP/1.1", upstream: "http://[::1]:8000/blog", host: "www.example.com", referrer:
"http://www.example.com/"
and below is my Nginx config file (i am new to nginx and i really want this done).
server {
listen 80;
listen [::]:80 ipv6only=on default_server;
server_name www.example.com example.com;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8000/;
proxy_http_version 1.1;
proxy_set_header "Connection" "";
proxy_set_header Upgrade $http_upgrade;
client_max_body_size 20m;
proxy_read_timeout 600s;
}
location ^~ /css {
autoindex on;
alias /home/saidjillo/webcitey/public/css;
}
location ^~ /media_query {
autoindex on;
alias /home/saidjillo/webcitey/public/css/media_query;
}
location ^~ /js {
autoindex on;
alias /home/saidjillo/webcitey/public/js;
}
location /images {
alias /home/saidjillo/webcitey/images;
autoindex on;
}
}
Someone to help with this problem. I am working from a very remote area where getting technical assistance like this one is a tricky business.
I am using pm2
to serve my nodejs.