How to configure multiple static directories in nginx?
To configure multiple static directories, you need to use multiple location directives in the nginx configuration file. Here is an example:
server {
listen 80;
server_name example.com;
root /var/www;
location / {
index index.html;
}
location /static1 {
alias /path/to/static1;
expires 7d;
}
location /static2 {
alias /path/to/static2;
expires 7d;
}
}
In the mentioned configuration, /static1 and /static2 are two different URL paths that correspond to the static file directories /path/to/static1 and /path/to/static2. Both of these static file directories will be served by the nginx server and will have the Expires field in the response headers set to 7 days.
Please note that when using the alias directive to specify a static file directory, the trailing slash / at the end of the path is required. Otherwise, Nginx will append the requested URL path after the path.