2016-12-05 45 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; 
    } 
... 
}