nginx根据域名动态配置主目录

in 前端 with 0 comment
server {
    listen 80;
    listen [::]:80;
    server_name    ~^(?<dir>.+)\.app\.example\.com$;
    root /var/www/$dir;

    index index.html index.htm;

    charset utf-8;

    location / {
      return 200 "The dir $dir r:$realpath_root d:$document_root";
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log   /var/log/nginx/example.com.log;
}

按照上面的配置,可以动态配置主目录。

如果想不同的子目录使用不同的项目根目录的话,可以试试alias

location ^~ /children/ {
    alias /usr/share/nginx/html/children/public;
}

不过这种情况下,laravel的路由可能会受到影响(未测试)

Comments are closed.