nginx 怎么根据不同子域名对应不同目录的资源文件 ?

浏览:52日期:2022-07-22

问题描述

例如:a.example.com/index.html 对应 /a-direcoty/index.html,而b.example.com/index.html 对应 /b-direcoty/index.html

问题解答

回答1:

server {listen 80;server_name ~^(?<subdomain>.+).example.com$;index index.html index.htm;root /$subdomain-direcoty/;}回答2:

nginx配置文件可以设置server段,在server中设置server_name来指定域名。所以你这种情况就设置两个server,分别是两个域名,然后再设置root为具体目录

相关文章: