要配置多个静态目录,你需要在nginx的配置文件中使用多个location指令。下面是一个例子:
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; } }
在上面的配置中,/static1
和/static2
是两个不同的URL路径,对应的静态文件目录分别是/path/to/static1
和/path/to/static2
。这两个静态文件目录都会被nginx服务器提供,并且会设置响应头中的Expires
字段为7天。
请注意,使用alias
指令来指定静态文件目录时,路径末尾的斜杠/
是必需的,否则nginx将会在路径后面附加请求的URL路径。