在 Nginx 中配置域名指向需要编辑 Nginx 的配置文件。在大多数情况下,Nginx 的主配置文件位于 /etc/nginx/nginx.conf 或 /etc/nginx/conf/nginx.conf。
打开配置文件后,您可以在 http 块内部的 server 块中配置域名指向。可以使用 server_name 指令来指定域名,然后在 location 块中定义该域名对应的页面或目录。
server {
listen 80;
server_name sub1.example.com;
root /var/www/vue-app/sub1;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
server {
listen 80;
server_name sub1.example.com;
root /var/www/vue-app/sub2;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}