在 Ubuntu 上配置虚拟主机
一 准备与通用步骤
二 配置 Apache 虚拟主机
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>
三 配置 Nginx 虚拟主机
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/example.com;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/example.com;
}
}
四 启用 HTTPS 与常见问题