简体   繁体   中英

Can I add different conf file per directory on Nginx?

I want to add different configuration file(s) to different directories. For example:

root /var/www/root/html

location / {
    root /var/www/root/html
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    include a.conf
    include phphandler.conf
}
location /dir1/ {
    root /var/www/dir1/html
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    include b.conf
}
location /dir2/ {
    root /var/www/dir2/html
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    include c.conf
    include phphandler.conf
}

So each directory has own .conf file (egaconf, b.conf) which contains their own php handling options, error handling options etc. and there is common conf file (phphandler.conf) which contains configuration that applies on all subdirectories.

Will this work? I want to seperate error pages and configuaration files for each subdirectories.

Also, will updating nginx restore /site-available/default to theit default configuation?

Answer to your question is yes it will be work, but don't do it in location /

in your main nginx.conf you have to write paths to include

for example now you have only one include /etc/nginx/sites-enabled/*;

just add another one include /etc/nginx/yourdir/*;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM