在 Debian 系统里,“域名跳转”通常指通过 Web 服务器(Nginx / Apache)把域名指向另一个域名或路径。下面按常见场景给你说明。
sudo apt update
sudo apt install nginx
假设:
old.example.comnew.example.com创建或编辑配置文件:
sudo nano /etc/nginx/sites-available/redirect.conf
内容示例:
server {
listen 80;
server_name old.example.com;
return 301 https://new.example.com$request_uri;
}
sudo ln -s /etc/nginx/sites-available/redirect.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
✅ 访问 http://old.example.com 会自动跳转到 https://new.example.com
sudo apt install apache2
sudo a2enmod rewrite
编辑虚拟主机:
sudo nano /etc/apache2/sites-available/redirect.conf
内容:
<VirtualHost *:80>
ServerName old.example.com
Redirect permanent / https://new.example.com/
</VirtualHost>
sudo a2ensite redirect.conf
sudo systemctl reload apache2
如果只是让域名访问另一个域名,而不是跳转页面:
old.example.com CNAME new.example.com
⚠️ 注意:
www、api 等子域名server {
listen 80;
server_name example.com;
return 301 https://example.com/blog$request_uri;
}
先申请 SSL(推荐 Let’s Encrypt):
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx
Certbot 会自动帮你配置 HTTPS → HTTP 跳转。
| 问题 | 排查 |
|---|---|
| 跳转不生效 | nginx -t 检查配置 |
| 浏览器缓存 | 用无痕模式 |
| 多个 server_name | 确保唯一 |
| 端口被占用 | ss -lntp |
我可以给你完全针对你服务器的配置示例。