nginx - Nginx 配置中静态位置的多个位置

标签 nginx

我的应用程序将在两个位置提供静态文件,一个是/my/path/project/static,另一个是/my/path/project/jsutils/static。

我很难让网络服务器在两个目录中查找静态内容。这是我在我的应用程序的 nginx 配置文件中的静态位置条目。

    location ^~ /static {
        root   /my/path/project/static;
        alias /my/path/project/jsutils/static;
       index  index.html index.htm;
    }

我收到一条错误消息:“alias”指令是重复的,“root”指令是之前指定的。

我不确定如何让 nginx 在这两个路径中查看静态内容。

预先感谢您的任何帮助。

最佳答案

location ^~ /static {
    root /my/path/project/static;
    index index.html index.htm;
    try_files $uri $uri/ @secondStatic;
}

location @secondStatic {
    root /my/path/project/jsutils/static;
}

因此,首先将在/my/path/project/static 中搜索文件,如果在那里找不到,则将触发 secondStatic 位置,将根更改为/my/path/project/jsutils/static。

关于nginx - Nginx 配置中静态位置的多个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15737440/

相关文章:

django - 如何通过 Amazon EC2 使用 Gunicorn 设置 Nginx 代理缓冲?

nginx - 带有Nginx的ElasticBeanstalk MultiContainer docker

express - 使用 aws elastic beantalk 将非 www 重定向到 www

python - AWS EB docker 应用程序 : why to configure nginx twice?

php - 安装 processmaker 3.2.3 的堆栈 N220

javascript - Open.window() Document.referrer 从 HTTPS 站点到 HTTP 站点为空

nginx - 禁止访问 Monterey 上的/Users/user/中的文件夹

nginx - 将 TLS 应用于工作入口会导致默认后端 - 404

php - 无法在 CentOS 6.4 上使用 NGINX 和 php-fpm 使用 PHP 创建文件

php - 在 Apache/Nginx 设置中刷新输出缓冲区