nginx怎么配置多个静态目录

   2025-02-13 7410
核心提示:要配置多个静态目录,你需要在nginx的配置文件中使用多个location指令。下面是一个例子:server {listen 80;server_name example

要配置多个静态目录,你需要在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路径。

 
 
更多>同类维修知识
推荐图文
推荐维修知识
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  网站留言