I use nginx as proxy server, backend are socketio services. Follow the document , nginx configuration.
upstream socketio {
ip_hash;
server server1:3000;
server server1:3001;
server server2:3100;
server server2:3101;
}
But for this configuration, same client request always proxy to same backend server.
If want same server request proxy to different backend server, have tried hash directive but doesn't work
upstream socketio {
hash "${remote_addr}${remote_port}";
Any solution?
Related
This is my nginx upstream backend config,
upstream backend {
#ip_hash;
server unix:/run/gunicorn.sock;
server private_ip:80;
server private_ip:80;
server private_ip:80;
server private_ip:80;
server private_ip:80;
}
After creating the new instance in AWS I need to add that instance private IP address in this upstream backend automatically. it is possible or not.
Imagine that we have a web application that is running in three different servers. And we have a NginX server that has a load balancer and redirects requests to these three servers.
So what happens to requests when the NginX server is no longer running? Are they redirect to one of the servers? If not how could we redirect them to one of the servers?
If one of the load balancing instances is down, requests will still get routed to that server, because nginx has no way of knowing upstream instance is failing. You'll get 502 Bad Gateway for one out of three requests.
To avoid down servers getting requests, you can use nginx's health checks.
NGINX and NGINX Plus can continually test your upstream servers, avoid the servers that have failed, and gracefully add the recovered servers into the load‑balanced group.
In your app, you can have a path /health_check that responds with 200 Status Code if the instance is OK and use this configuration.
http {
upstream backend {
server backend1.example.com;
server backend2.example.com;
}
server {
location / {
proxy_pass http://backend;
health_check uri=/health_check;
}
}
}
I have an nginx server which proxies requests to a service which works on https.
Nginx server is in the same private network with my services which use it.
Can I use http between my service and nginx or in this case nginx will not encrypt traffic between nginx and external service?
So I have:
MyService --privite network http request--> Nginx --https--> exteranl service.
server {
listen 8080;
location / {
proxy_pass https://example.com;
}
}
My concern is that I send http request and expect encrypted data somewhere along the way.
Will it realy work as Nginx --https--> external or it will be Nginx --http--> external?
After modifying the nginx up configuration to mark a server as a backup from this :
upstream backend {
server backup1.example.com:8080;
server backup2.example.com:8080;
}
to this
upstream backend {
server backup1.example.com:8080;
server backup2.example.com:8080 backup;
}
what happens to existing connections on backup2.example.com:8080? will they immediately be routed to backup1.example.com or will they persist on backup2.example.com until the connection is disconnected?
I use OpenResty® to proxy my backend server.
The process is client->proxy server->backend server
The question is the comment of the code:
stream {
upstream teststream{
server xxxxxx:1234;
}
server {
listen 1234;
proxy_pass teststream;
content_by_lua_block {
#how to get the proxy server socket port between proxy server and backend server
}
}}
Client sends a message to proxy server, then proxy server forwards the message to backend server.The proxy server will new a socket to connect the backend server, so how to get the proxy server socket port between proxy server and backend server in content_by_lua_block?
There is https://github.com/openresty/lua-upstream-nginx-module
get_servers
syntax: servers = upstream.get_servers(upstream_name)
Get configurations for all the servers in the specified upstream
group. Please one server may take multiple addresses when its server
name can be resolved to multiple addresses.
The return value is an array-like Lua table. Each table entry is a
hash-like Lua table that takes the following keys:
addr
socket address(es). can be either a Lua string or an array-like Lua
table of Lua strings.
...
BTW, both proxy_pass and content_by_lua_block are content phase directives.
Only one will work. Please take a look at this post https://groups.google.com/forum/#!topic/openresty-en/DRocQpM4mVY