Meteor Up load balancer - nginx

My meteor application is deployed with mup.js
I would like to use balance loader for several reasons. (No downtime deployment, better user experience)
In the docs. there is a Swarm what makes a cross server load balancing, but I would have separated app containers at the same server. And they just running on different ports, what NGINX balancing
Status: Have started different app containers at the same server, but can not configure the nginx.
Having 2x mup file (1. mup.js, mup-support.js) They are pretty same, but the support runs only the app container, and connects it to the db.
mup.js:
proxy: {
domains: "domain.com",
nginxServerConfig: "./staging.nginx.conf",
loadBalancing: true,
ssl: {
// ... config
}
}
staging.nginx.conf:
upstream pass_servers {
server container1
server container2
}
server {
server_name domain.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
include /etc/nginx/vhost.d/domain.com;
location / {
proxy_pass http://pass_servers.com;
}
}
Result: crashed nginx
Question: Is the logic fine, or should I go in a different way? If the logic is fine, what am I missing?

Related

nginx path omitted and sources cannot be found

I am currently configuring a nginx reverse proxy.
The docker instance of nextcloud is available on Port 8891
server {
listen 8888 ssl http2;
...
location /nextcloud/ {
proxy_pass http://0.0.0.0:8891/;
}
}
however when I try to navigateto the url, I have the problem, that the stylesheets etc. are not available under /nextcloud/*
instead they are getting fetched from /core/*.
How can I archive, that the sources like server.css is getting fetched from /nextcloud/, and basically the whole nextcloud web app is available under /nextcloud/?

Nginx config invalid parameter even though it is in documentation

I am tryin to run nginx latest version with the following configuration, but I get nginx: [emerg] invalid parameter "route=bloomberg" in /etc/nginx/nginx.conf:13
docker run --rm -ti -v root_to_local_nginx_directory:/etc/nginx:ro -p 3080:80 --name=mynginx --entrypoint nginx nginx
# nginx.conf file inside root_to_local_nginx_directory
http {
map $cookie_route $route_from_cookie {
~.(?P<version>w+)$ $route;
}
split_clients "${remote_addr}" $random_route {
50% server bloomberg.com route=bloomberg;
* server yahoo.com route=yahoo;
}
upstream backend {
zone backend 64k;
server bloomberg.com route=bloomberg;
server yahoo.com route=yahoo;
sticky route $route_from_cookie $randomroute;
}
server {
# ...
listen 80;
location / {
proxy_set_header Host $host;
proxy_pass http://backend;
}
}
}
Why is this? According to the documentation this should be correct http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream.
The route=string parameter of the server directive within the upstream context is considered to be an enterprise-grade feature, and is thus only available through the commercial subscription, in NGINX Plus, not in OSS NGINX. (If you look closer into the documentation, you'll notice it's grouped together with the other parameters under a separate "available as part of our commercial subscription" subsection.)
Additionally, you're also trying to use some similar "server" parameters within the split_clients context as if they were actual directives interpreted by nginx, even though everything is supposed to be string literals in that context; it's unclear whether or not that part is responsible for any errors, but even if not, it's a bad style to introduce such confusion into your configuration.
References:
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server
http://nginx.org/en/docs/http/ngx_http_split_clients_module.html#split_clients
https://www.nginx.com/products/nginx/
The reason why you are seeing the error is because the split_clients module does not support the route parameter. Alternatively, you can do something along the lines:
upstream bloomberg {
server bloomberg.com route=bloomberg;
}
upstream yahoo {
server yahoo.com route=yahoo;
}
split_clients "${remote_addr}" $random_route {
50% bloomberg;
* yahoo;
}

Nginx: Setting up SSL-passthorugh

I'm trying to configure SSL-passthrough for multiple webapps using the same nginx server (nginx version: nginx/1.13.6), but when restarting the nginx server, I get an error complaining that
nginx: [emerg] "stream" directive is duplicate
The configuration I have is the following:
2 files for the ssl passthrough that look like this:
server1.conf:
stream {
upstream workers {
server 192.168.1.10:443;
server 192.168.1.11:443;
server 192.168.1.12:443;
}
server {
listen server1.com:8443;
proxy_pass workers;
}
}
and server2.conf:
stream {
upstream workers {
server 192.168.1.20:443;
server 192.168.1.21:443;
server 192.168.1.22:443;
}
server {
listen server2.com:8443;
proxy_pass workers;
}
}
If I remove one of the two files, then nginx starts correctly.
How can this be achieved?
Thanks,
Cristi
Streams work on Layer 5, and cannot read encrypted traffic (which is Layer 6 on the OSI model), and thus cannot tell apart requests hitting server1.com and server2.com unless they are pointing to different IPs.
This can be solved by one of the following solutions
Decrypt the traffic on nginx, then proxy-pass it to backend processes/wockers using HTTP.
Bind server1.com to a port that is different to server2.com.
Get an additional IP address and bind server2.com on that.
Get an additional load balancer and move server2.com there.

Using nginx to serve local files instead of remote files

Say I'm accessing www.mywebsite.com.
This website fetches the following asset:
http://www.mywebsite.com/styles/app.css
I want to access the website exactly as I normally would, with one exception:
Whenever my browser makes a request to /styles/app.css, instead of fetching it from http://www.mywebsite.com, I want to fetch it from http://localhost:3000/mywebsite/.
So instead it should be fetching:
http://localhost:3000/mywebsite/styles/app.css
Is this possible with nginx?
I tried to do it using the following server config:
{
...
server {
listen 80;
server_name mywebsite.com;
location /styles/ {
proxy_pass http://localhost:3000/mywebsite/styles/;
}
}
But even after restarting nginx (sudo nginx -s quit, sudo nginx), nothing seems to have changed.
When I browse to www.mywebsite.com/styles/app.css, I still get the same old app.css being retrieved from the server, rather than my local one.

nginx on separate server proxy_pass to multiple rails apps with sub URI on passenger standalone in different boxes

I have this requirement, where there are multiple rails applications. Each application is deployed in two app servers, (app1 and app2) and they are load balanced through nginx on a separate server (lb).
The lb box contains plain vanilla nginx without passenger plugins.
The rails applications are deployed on passenger stand alone.
All the rails applications need to run on the same domain but with different sub_uri, like below
http://www.example.com/rails1
http://www.example.com/rails2
I have the lb box nginx configuration something like below.
http {
...
upstream rails1_cluster {
ip_hash;
server app1.server:3001;
server app2.server:3001;
}
upstream rails2_cluster {
ip_hash;
server app1.server:3002;
server app2.server:3002;
}
...
server {
server_name www.example.com;
...
...
location /rails1 {
proxy_pass http://rails1_cluster;
...
}
location /rails2 {
proxy_pass http://rails2_cluster;
...
}
....
}
}
With this setup, the app running on passenger standalone in app1 and app2 throws an error that it is unable to find any route /rails1/.
This article "How To Deploy Phusion Passenger To A Subdirectory, Routing Errors, And Restarting" tries to address the same problem, but it suggests changing the routes, which I don't wish to do. The Rails applications am dealing with are of same code base but customized for specific instances catering to specific client.
In passenger plugin for Nginx server, there is a passenger_base_uri which helps in setting a sub URI for the app. What is the equivalent of the same in case of passenger stand alone? Or am I missing something fundamental here? Any help, suggestions would help.
Give this a try, using the rewrite module:
location /rails2 {
rewrite "/rails2/" / break;
proxy_pass http://rails2_cluster;
}
It's a regex so might go on fire if the url actually contains that. Also this one does not yet work for addresses without the trailing slash, so check this.

Resources