在 CentOS 上配置“多域名”通常分几种常见场景,我先按**最常见的 Web 服务(Nginx / Apache)**给你讲,如果你是其他用途(邮件、反向代理、Docker 等)可以再告诉我。
sudo yum install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
sudo mkdir -p /var/www/domain1.com
sudo mkdir -p /var/www/domain2.com
sudo vi /etc/nginx/conf.d/domain1.conf
domain1.conf
server {
listen 80;
server_name domain1.com www.domain1.com;
root /var/www/domain1.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
同理创建 domain2.conf
server {
listen 80;
server_name domain2.com www.domain2.com;
root /var/www/domain2.com;
index index.html;
}
sudo nginx -t
sudo systemctl reload nginx
sudo yum install httpd -y
sudo systemctl enable httpd
sudo systemctl start httpd
sudo vi /etc/httpd/conf.d/domain1.conf
<VirtualHost *:80>
ServerName domain1.com
DocumentRoot /var/www/domain1.com
</VirtualHost>
sudo systemctl restart httpd
使用 Let’s Encrypt:
sudo yum install certbot python2-certbot-nginx -y
sudo certbot --nginx -d domain1.com -d www.domain1.com
Apache:
sudo certbot --apache
ping domain.com)sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
如果你能告诉我:
我可以直接给你一份可复制的配置。