Linux 域名与服务器配置全流程
一 准备与规划
二 域名 DNS 解析配置
192.0.2.10 your_domain.test。三 Web 服务器与虚拟主机配置
| 项目 | Nginx | Apache |
|---|---|---|
| 安装(Debian/Ubuntu) | sudo apt-get update && sudo apt-get install nginx | sudo apt-get update && sudo apt-get install apache2 |
| 安装(RHEL/CentOS) | sudo yum install nginx 或 dnf install nginx | sudo yum install httpd 或 dnf install httpd |
| 站点目录 | /var/www/your_domain | /var/www/your_domain |
| 配置目录/文件 | /etc/nginx/nginx.conf;/etc/nginx/sites-available/your_domain.conf(软链到 sites-enabled) | /etc/apache2/sites-available/your_domain.conf |
| 虚拟主机示例 | server { listen 80; server_name your_domain www.your_domain; root /var/www/your_domain; index index.html; location / { try_files $uri $uri/ =404; } } | <VirtualHost *:80> ServerName your_domain ServerAlias www.your_domain DocumentRoot /var/www/your_domain <Directory /var/www/your_domain> Options Indexes FollowSymLinks AllowOverride All Require all granted ErrorLog ${APACHE_LOG_DIR}/your_domain-error.log CustomLog ${APACHE_LOG_DIR}/your_domain-access.log combined |
| 启用站点 | sudo ln -s /etc/nginx/sites-available/your_domain.conf /etc/nginx/sites-enabled/ | sudo a2ensite your_domain.conf |
| 检查语法 | sudo nginx -t | sudo apache2ctl configtest |
| 重启服务 | sudo systemctl restart nginx | sudo systemctl restart apache2 |
四 防火墙与端口开放
五 验证与常见问题排查