我在 Ubuntu20 上運行 Nginx,其 proxy_passhttps://example.com
是0.0.0.0:8000
一個 docker 容器。當我點擊https://example.com/literally/any/path/at/all
代理時,它會按預期工作,但是當我點擊根路徑時,https://example.com
我會得到 301 重定向到https://docker:8000
.我不明白為什麼子路徑被代理得很好,但根路徑卻被重定向了。
我的 Nginx 網站設定:
upstream docker {
server 0.0.0.0:8000;
}
server {
listen 80;
server_name example.com www.example.com mail.example.com;
location /.well-known {
alias /ssl/well-known;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name example.com www.example.com mail.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://docker;
}
}