我在使用域名连接到我的 VPS 服务器时遇到问题。我在 Debian 10 Docker 服务器上安装了 SSL 证书,并且 https 仅适用于 IP 地址,当我尝试使用域名连接时,它显示 503 未找到后端。我尝试在不使用 nginx 的情况下执行此操作,现在我使用 nginx 配置它,此时它显示“重定向过多”。我尝试了很多解决方案,但没有找到类似的东西。
这是我的 nginx.conf 脚本:
events {
worker_connections 1024;
}
http {
upstream web {
server web:8000;
}
server {
listen 80;
listen [::]:80;
server_name domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain.com;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
location / {
proxy_pass http://web;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_buffering off;
proxy_redirect off;
}
}
}
这是我的docker-compose.yml:
version: '3'
services:
web:
build: .
ports:
- "8000:8000"
volumes:
- .:/app
command: python3 manage.py runserver 0.0.0.0:8000
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- /etc/nginx/nginx.conf:/etc/nginx/nginx.conf
- /etc/letsencrypt:/etc/letsencrypt
depends_on:
- web
restart: on-failure
如何在域上正确运行 SSL 服务器?