域名绑定与 Docker 容器部署指南
1. 获取云服务器公网 IP
2. 配置域名 DNS 解析
- 主机记录:@
- 类型:A
- 值:服务器公网 IP
- TTL:默认
3. 安装 Nginx
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
4. 配置 Nginx 反向代理
sudo nano /etc/nginx/sites-available/【你的域名】
server {
listen 80;
server_name 【你的域名】 www.【你的域名】;
location / {
proxy_pass http://localhost:8080;
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;
}
}
sudo ln -s /etc/nginx/sites-available/【你的域名】 /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
5. 配置防火墙
sudo ufw status
sudo ufw allow 'Nginx Full'
sudo ufw status
6. 测试域名访问
在浏览器访问:http://【你的域名】
7. 配置 HTTPS(可选)
sudo apt install certbot python3-certbot-nginx -y
sudo certbot –nginx -d 【你的域名】 -d www.【你的域名】
sudo certbot renew –dry-run
关键点: 执行sudo certbot renew –dry-run出错误,可执行sudo less /var/log/letsencrypt/letsencrypt.log查看日志。 出现邮箱错误,检查是否是符合下列标准:user.example.com(去掉@),然后使用下面命令修正:
sudo certbot –nginx -d 【你的域名】 -d www.【你的域名】 –email your-email@user.example.com
参考资源
- Nginx 官方文档
- Let’s Encrypt 官方文档
注:所有【你的域名】部分需替换为实际域名
评论前必须登录!
注册