uwsgicluster - no live upstreams while connecting to upstream client - nginx

Below simple nginx config for cluster, then I turn off 192.168.1.77:3032 server.
From time to time I catch 502 error and "no live upstreams while connecting to upstream client" in logs, while "server unix:///var/tmp/site.sock backup;" working and as I guess must handle request but nginx don't find it as live. What could be the problem?
nginx config:
upstream uwsgicluster {
server 192.168.1.77:3032;
server unix:///var/tmp/site.sock backup;
}
server {
listen 80;
server_name site.com www.site.com;
access_log /var/log/nginx/sire.log;
error_log /var/log/nginx/site-error.log;
location / {
uwsgi_pass uwsgicluster;
include uwsgi_params;
}
}
If I remove 192.168.1.77:3032 server
from upstream and restart nginx it works fine, but with switched off 192.168.1.77:3032 server errors occurs periodically

I think that nginx will still try both of the servers in the upstream block even if one isn't working. When it fails to connect to one of them, it will try the other one, but will still log the error you are seeing.
By default, the proxy_next_upstream setting will try the next upstream server on error or timeout. You can override this:
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream
Are you only seeing error logs, or are you also seeing undesired behavior/load-balancing?

Related

Nginx reverse proxy - Internal servers separated by trailing slash

I'm a newbie at Nginx, and have been searching a lot for the right answer to my question, but couldn't find it; not because it is not there, but my newbie condition limits me to adapt a generic solution to my issue.
The situation is this:
I have a Mantis Bug Tracker in my private LAN (http://10.111.111.12).
On the other hand, i have an OwnCloud website also on my LAN (IP 10.111.111.5), with URL http://10.111.111.5/owncloud/.
What i want to do is to deploy a Nginx Reverse Proxy that handles all requests from Internet at publicdomain.com, and use trailing slash for each internal webserver. The desired result would be:
http://www.publicdomain.com/bugtracker -> redirects to http://10.111.111.12/index.php
http://www.publicdomain.com/cloud -> redirects to http://10.111.111.5/owncloud/ (note that "cloud" is preferred over "owncloud")
On the future, it is necessary to continue using trailing slash for other web servers to be deployed.
Questions are:
is this scenario possible? if so, is it enough with configuring nginx or I have to reconfigure internal web servers as well?
I really appreciate your help, by indicating me a possible solution or pointing me to the right direction on previous posts.
Thanks a lot in advance.
Yes it is possible to achieve such configuration and it's commonly used when NGINX is acting as a reverse proxy. You can use this configuration as an inspiration for building your own:
upstream bugtracker {
server 10.111.111.12;
}
upstream cloudupstream {
server 10.111.111.5;
}
server {
listen 80;
location /bugtracker/{
proxy_pass http://bugtracker;
}
location /cloud/{
proxy_pass http://cloudupstream/owncloud;
}
}
What's happening over here is that nginx will be listening on port 80 and as soon as a request comes for path /bugtracker, it will automatically route the request to the upstream server mentioned above. Using this you can add as many upstream servers and location blocks as you want.
Reference: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
Thanks a lot Namam for your quick answer. However, it isn't working yet. It seems that "server" at upstream directive does not allow slash, like this:
server 10.111.111.5/owncloud;
If i used it, i obtained
nginx: [emerg] invalid host in upstream "10.111.111.5/owncloud" in /etc/nginx/nginx.conf:43
I started with the first upstream bugtracker, only, and nginx.conf like this:
upstream bugtracker {
server 10.111.111.12;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
location /mstic{
proxy_pass http://bugtracker;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
After that, when accesing to my Nginx Reverse proxy http://10.111.111.10/mstic/ i obtain the following:
Not Found The requested URL /mstic/ was not found on this server.
and no further details on error or access logs.
Thanks a lot in advance for any extra help you could bring me.

nginx failed (32: Broken pipe) while sending request to upstream,

When uploading files less than 8 MB the upload is fine with my NGINX config.
Uploading files with ~8MB fails.
client_max_body_size 10M;
server {
listen 443 default_server ssl;
server_name ~. "";
location {
proxy_pass http://localhost:8080;
}
}
Checking the nginx error logs I can see this
nginx failed (32: Broken pipe) while sending request to upstream,
This nginx errors then shows 502 Bad Gateway error to the client.
In my case, the problem is with the Upstream server (which is NGINX Unit)
I had to set the max_body_size from there and the upload is not working fine.
Bottom line here is to check the Upstream server first.
Related to https://forum.nginx.org/read.php?2,284631,284631#msg-284631

Nginx proxy_next_upstream with different URI modification

We have a need to set up multiple up-stream server, and use proxy_next_upstream to a backup, if the main server returns 404. However, the URI for up-stream backup server is different than the one towards main server, so I don't know whether this can be possible.
In detail, below config snippet works fine (if URIs are the same to all up-stream servers):
upstream upstream-proj-a {
server server1.test.com;
server server2.test.com backup;
}
server {
listen 80;
listen [::]:80;
server_name www.test.com;
location /proj/proj-a {
proxy_next_upstream error timeout http_404;
proxy_pass http://upstream-proj-a/lib/proj/proj-a;
}
For a request of http://test.com/proj/proj-a/file, it will first try to request http://server1.test.com/lib/proj/proj-a/file, if return 404 or timeout, then try http://server2.test.com/lib/proj/proj-a/file. This is good.
However, now for server2, it can only accept URL like http://server2.test.com/lib/proj/proj-a-internal/file, which is different than the URI towards the main server. If only considering the backup server, I can write like below:
proxy_pass http://server2.test.com/lib/proj/proj-a-internal
However looks like I can not have different proxy_pass for different upstream server combining proxy_next_upstream.
How can I achieve this?
I found a work-around using simple proxy_pass, and set local host as the backup upstream server, then do rewrite on behalf of the real backup upstream server.
The config is like below:
upstream upstream-proj-a {
server server1.test.com:9991;
# Use localhost as backup
server localhost backup;
}
server {
listen 80;
listen [::]:80;
resolver 127.0.1.1;
server_name www.test.com;
location /lib/proj/proj-a {
# Do rewrite then proxy_pass to real upstream server
rewrite /lib/proj/proj-a/(.*) /lib/proj/proj-a-internal/$1 break;
proxy_pass http://server2.test.com:9992;
}
location /proj/proj-a {
proxy_next_upstream error timeout http_404;
proxy_pass http://upstream-proj-a/lib/proj/proj-a;
}
}
It works fine, but the only side-effect is that, when a request needs to go to the backup server, it creates another new HTTP request from localhost to localhost which seems to double the load to nginx. The goal is to transfer quite big files, and I am not sure if this impacts performance or not, especially if all the protocols are https instead of http.

Ngixn load balancer keep changing original URL to load balanced URL

I have met an annoying issue for Nginx Load Balancer, please see following configuration:
http {
server {
listen 3333;
server_name localhost;
location / {
proxy_pass http://node;
proxy_redirect off;
}
}
server {
listen 7777;
server_name localhost;
location / {
proxy_pass http://auth;
proxy_redirect off;
}
}
upstream node {
server localhost:3000;
server localhost:3001;
}
upstream auth {
server localhost:8079;
server localhost:8080;
}
}
So what I want is to provide two load balancers, one is to send port 3333 to internal port 3000,3001, and second one is to send request to 7777 to internal 8079 and 8000.
when I test this setting, I noticed all the request to http://localhost:3333 is working great, and URL in the address bar is always this one, but when I visit http://localhsot:7777, I noticed all the requests are redirected to internal urls, http://localhost:8080 or http://localhost:8079.
I don't know why there are two different effects for load balancing, I just want to have all the visitors to see only http://localhost:3333 or http://localhost:7777, they should never see internal port 8080 or 8079.
But why node server for port 3000 and 3001 are working fine, while java server for port 8080 and 8079 is not doing url rewrite, but only doing redirect?
If you see the configuration, they are exactly the same.
Thanks.

nginx "500 internal server error" on large request

I am sending a 14K request to my backend through nginx and I get the following error:
500 Internal Server Error
I am running nginx 1.6.2 and if I send my request directly to my backend, everything works fine and the request takes about 3-4 seconds round trip.
This is my nginx config:
$ cat /etc/nginx/nginx.conf
events {
worker_connections 1024;
}
http {
proxy_temp_path /tmp/nginx;
upstream my_servers {
server <server1>:9000 down;
server <server2>:9000 down;
server <server3>:9000 down;
server <server1>:9001;
server <server2>:9001;
server <server3>:9001;
}
server {
access_log /var/log/nginx/access.log combined;
listen 9080;
location / {
proxy_pass http://my_servers;
}
}
}
Any idea on what is going on? I can't be hitting any default timeouts at 3-4 seconds I assume?
BTW, when I tried looking at the access log file, it was empty.
The issue was related to permissions for client_body_temp_path as described here:
https://wincent.com/wiki/Fixing_nginx_client_body_temp_permission_denied_errors

Resources