# 域名与 HTTPS 配置 (bid.hao.work) > 目标:让 `https://bid.hao.work` 可访问当前目录,并让 `https://bid.hao.work/docs` 展示文档结构页面。 ## 1. DNS 设置 - 增加 A 记录:`bid` → 服务器公网 IPv4 - 如有 IPv6,再增加 AAAA 记录 - 等待 DNS 生效(一般 5-30 分钟) ## 2. Nginx 静态站点配置 ### 2.1 站点配置文件 路径:`/etc/nginx/sites-available/bid.hao.work` ``` server { server_name bid.hao.work; root /root/ca_v3/bid; index index.html; location = /docs { return 301 /docs/; } location /docs/ { try_files $uri $uri/ =404; } location / { try_files $uri $uri/ /index.html; } } ``` ### 2.2 启用站点并重载 ```bash sudo ln -s /etc/nginx/sites-available/bid.hao.work /etc/nginx/sites-enabled/bid.hao.work sudo nginx -t sudo systemctl reload nginx ``` ### 2.3 目录权限(Nginx 访问 /root) 如果站点根目录位于 `/root/ca_v3/bid`,需要为 `www-data` 赋予只读访问权限: ```bash sudo apt-get install -y acl sudo setfacl -m u:www-data:rx /root sudo setfacl -m u:www-data:rx /root/ca_v3 sudo setfacl -R -m u:www-data:rx /root/ca_v3/bid sudo setfacl -d -m u:www-data:rx /root/ca_v3/bid ``` ## 3. 申请免费 HTTPS 证书 (Certbot) ```bash sudo certbot --nginx -d bid.hao.work --non-interactive --agree-tos --register-unsafely-without-email --redirect ``` ## 4. 访问验证 ```bash curl -I https://bid.hao.work curl -I https://bid.hao.work/docs/ ``` ## 5. 常见问题 - DNS 未生效:等待或刷新本地 DNS 缓存 - HTTPS 失败:检查 80/443 端口是否可访问 - 403/500:检查目录权限与 ACL 设置