Question
connect() failed (111: Connection refused) while connecting to upstream
I saw a similar topic to this one with the same title, but i rekon the issue is a lot different, and i thought it would be better to make a separate question rather than filling up responses from that one. So let’s go:
Full error:
[error] 1209#1209: *2283 connect() failed (111: Connection refused) while connecting to upstream, client: 178.222.123.190, server: app.multiunitpros.com, request: "GET /api/ HTTP/1.1", upstream:http://127.0.0.1:1337/", host: "app.multiunitpros.com"
After running sudo nginx -t i get this set of messages
nginx: [warn] conflicting server name “app.multiunitpros.com” on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Accessing this domain with /api gives 502 bad gateway
Error log provides this
[error] 1209#1209: *2283 connect() failed (111: Connection refused) while connecting to upstream, client: 178.222.123.190, server: app.multiunitpros.com, request: “GET /api/ HTTP/1.1”, upstream: “http://127.0.0.1:1337/”, host: “app.multiunitpros.com”
Here is my /etc/nginx/sites-available/app.multiunitpros.com
server {
server_name app.multiunitpros.com www.app.multiunitpros.com app.multiunitpros.com;
error_log /var/www/app.multiunitpros.com/logs/app.multiunitpros.com.error.log;
access_log /var/www/app.multiunitpros.com/logs/app.multiunitpros.com.access.log;
root /var/www/app.multiunitpros.com/public/dist;
index index.php index.html;
large_client_header_buffers 4 16k;
location /api {
proxy_pass http://localhost:1337;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass_request_headers on;
client_max_body_size 100M;
rewrite ^/api/?(.*) /$1 break;
}
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^((?!/api/).+)$ /index.html last;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/app.multiunitpros.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/app.multiunitpros.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.app.multiunitpros.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = app.multiunitpros.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name app.multiunitpros.com www.app.multiunitpros.com app.multiunitpros.com;
return 404; # managed by Certbot
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×