我正在使用 NGINX 对 Digital Ocean 上的 docker swarm 集群进行负载平衡。我已经swarmpit
安装好了,我想使用 SSL 证书和自定义端口对其进行反向代理,这样我就可以私下访问它并限制流量。
我没有使用任何自定义路径或任何花哨的东西。我实际上只是从子域下的根路径反向代理到容器。
页面确实加载了,但似乎根目录之外的任何内容都没有加载,并出现 404 或 401 错误。因此,页面似乎已损坏,只有根目录级别的内容正在加载。
Server Config
server {
listen #### ssl;
ssl_certificate /etc/letsencrypt/live/###.#####.###/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/###.#####.###/privkey.pem;
include snippets/ssl-params.conf;
include snippets/optimize-assets.conf;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'Upgrade';
proxy_cache_bypass $http_upgrade;
proxy_pass http://swarmpit;
}
}
Upstream Block
upstream swarmpit {
server ###.###.###.###:###;
server ###.###.###.###:###;
server ###.###.###.###:###;
server ###.###.###.###:###;
server ###.###.###.###:###;
}
我还在 nginx.conf 文件中设置了许多默认设置,例如
nginx.conf
...
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass_request_headers on;
...
我看到的是
404 响应示例
Request URL: https://###.#####.###:####/css/rc-slider.css
Request Method: GET
Status Code: 404 Not Found
Remote Address: ###.###.###.###:####
Referrer Policy: no-referrer-when-downgrade
Connection: keep-alive
Content-Length: 555
Content-Type: text/html
Date: Sat, 30 May 2020 05:50:54 GMT
Server: nginx/1.18.0
Accept: text/css,*/*;q=0.1
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Cookie: _ga=#####
DNT: 1
Host: ###.#####.###:####
Referer: https://###.#####.###:####/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: no-cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.125
我不确定为什么它不起作用,但经过大量谷歌搜索后,我找不到任何帮助,我确信这可能是一件简单的事情。任何帮助都值得感激。