0

我正在研究集群上的负载平衡。它工作得很好,但我意识到我希望能够通过在 url 中指定某个节点来请求它,例如我想要将请求发送到的实际节点domain.com/nodeX/request_uri/在哪里。nodeX我想这样做的原因是,我可以很容易地知道我在哪个节点上,如果我正在其中一个节点上工作,并且需要将此节点上的实际文件同步到其他节点, 当文件改变时。

现在它只有NextCloud在服务器上运行,在文件夹中,有一个与glusterfs/nextcloud/共享的数据目录,所以我需要复制的不是这些文件,而是“next-cloud 的核心文件”或者实际上是www 更改的目录。

这是(通常)主节点上的设置,`/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]+»/;
    }
}

每个从节点 ( nodeX, X > 0) 加载相同的配置,这是对它的总结:

server {
    listen 80 default_server; #Yep, no need for SSL in local network
    [...]
    include snippets/nextcloud.conf;
}

我已删除不相关的数据(例如add_headerroot)以保持清晰。每个节点(包括主节点)共享同一个snippet文件夹,通过 glusterfs 分发。这个文件snippet/nextcloud.conf是我需要帮助的文件。domain.com/nextcloud/如果我写的话,下一个云会自动重定向到domain.com/node0/nextcloud/,所以我需要一个解决方案来欺骗服务器,让它相信它正在运行,/nextcloud/只要它实际运行在nodeX.

这是我到目前为止所拥有的,它确实重定向了我:

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;
    }
}

所以我的问题一般是;是否可以删除 URI 的“/nodeX/”或任何其他内容?:)

笔记!/nodeX/当负载平衡器应该处理实际平衡时,可能缺少该部分。

4

0 回答 0