域名绑定服务器小白教程

域名绑定与 Docker 容器部署指南

1. 获取云服务器公网 IP

  1. 登录云服务提供商控制台
  2. 记录服务器公网 IP(例:123.456.78.90

2. 配置域名 DNS 解析

  1. 登录域名注册商控制台
  2. 添加 A 记录:
    • 主机记录:@
    • 类型:A
    • 值:服务器公网 IP
    • TTL:默认

3. 安装 Nginx

sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx

4. 配置 Nginx 反向代理

  1. 创建配置文件:
sudo nano /etc/nginx/sites-available/【你的域名】
  1. 配置内容:
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;
    }
}
  1. 启用配置:
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

参考资源

注:所有【你的域名】部分需替换为实际域名

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值