2016-12-05 44 views
1

我在Nginx上使用类似下面的内容作为“默认”vhost。我希望每个子域都有一个自己的目录。Nginx通配符根子域的后备

任何人都可以帮助一个后备(我是新来的)。如果目录/子域不存在,我想要某种自定义404.html页面。

谢谢!

server { 

    server_name ~^(.+).mysite.com$; 

    set $root_path $1; 

    root /var/www/$root_path/public; 
    index index.html index.php; 

    location/{ 
     try_files $uri /$uri /index.php?$args; 
    } 

    location ~ \.php$ { 
     #Include Nginx’s fastcgi configuration 
     include /etc/nginx/fastcgi.conf; 
     #Look for the FastCGI Process Manager at this location 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     client_max_body_size 100m; 
    } 

} 

回答

0

试试这个:

server { 
... 
    error_page 404 /your_custom_404.html; 
    location = /your_custom_404.html { 
     root /path/to/your_custom_404.html; 
     internal; 
    } 

    location/{ 
     try_files $uri $uri/ /index.php?$args =404; 
    } 
... 
}