I'm working on load balancing on a cluster. It works great, but I realized that I want to be able to request a certain node by specify it in the url, e.g domain.com/nodeX/request_uri/
where nodeX
is the actual node I want to send the request to. The reason why I want to do this, is so I can easily know which node I'm on, if I'm doing work on one of them, and need to sync the actual file(s) on this node to the other nodes, when files changes.
Right now it's only NextCloud running on the server, in the folder /nextcloud/
, with a data directory that is shared with glusterfs, so it's not these files I need to replicate, but the "core files of next-cloud" or actually any files in the www-directory that is changed.
This is (in general) the setup on the master node, `/etc/nginx/sites-available/default:
upstream cluster {
ip_hash;
server node1;
server node2;
[...]
server nodeX;
}
server {
listen 443 ssl http2 default_server;
[...]more unrelated configurations[...]
# This works as expected
location / {
proxy_pass http://cluster/;
}
# But this is where I need help:
# If location starts with /nodeX, where X is a number
location ^~ /node([0-9]+) {
# If location is master node (node0)
location /node0 {
# Include nextcloud configuration
include snippets/nextcloud.conf;
}
# Otherwise pass it on to the requested node
proxy_pass http://«node[0-9]+»/;
}
}
Every slave node (nodeX, X > 0
) loads the same configuration, and this is a sum-up of it:
server {
listen 80 default_server; #Yep, no need for SSL in local network
[...]
include snippets/nextcloud.conf;
}
I have removed unrelated data (such as add_header
, root
etc) to keep things clear. Every node (including master) shares the same snippet
-folder, which is distributed through glusterfs. This file snippet/nextcloud.conf
is the one I need help with. Next cloud will automatically re-direct to domain.com/nextcloud/
if I write domain.com/node0/nextcloud/
, so I need a solution to trick the server to belive it's running on /nextcloud/
whenever it's actually running in a sub-directory of nodeX
.
This is what I have so far, which do redirect me:
location ~ /(node[0-9]/?)nextcloud {
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# This is where I should be able to trick the
# server to think its running on /nextcloud/ even
# when its request is /nodeX/nextcloud
location ~ /(node[0-9]/?)nextcloud {
rewrite ^ /nextcloud/index.php$uri;
}
location ~ ^/(node[0-9]/?)nextcloud/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(node[0-9]/?)nextcloud/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(node[0-9]/?)nextcloud/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(node[0-9]/?)nextcloud/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js|woff|svg|gif)$ {
try_files $uri /nextcloud/index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
# Optional: Don't log access to assets
access_log off;
}
location ~* \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /nextcloud/index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
So my question in general is; Is it possible to remove the "/nodeX/" of the URI, or any other thing? :)
Note! It may be that the /nodeX/
part is missing, when the load balancer is supposed to deal with the actual balancing.