如何允许图像但拒绝其他所有内容?

时间:2019-01-13 02:37:20

标签: nginx

文件结构为

  1. LargerProject
    • Discord-OAuth2
      • config <-不想让任何人访问此
      • 静态<-此处的图像

当我不包括底部的2个位置规则时,将显示我的图像,但是可以访问我的配置。当我遵循以下规则时(我尝试了许多变体),我的图像返回404,我的配置返回403。

server {
    listen 80;

    location / {
    include /etc/nginx/mime.types;
        root /var/www/html/LargerProject;
        index index.php index.html index.htm;
    }

    location ^~ /Discord-OAuth2/static/ {
        allow all;
    }

    location ^~ /Discord-OAuth2/ {
        deny all;
    }
}

所有图像均未显示在我的网站上(使用Jinja的烧瓶服务器) 我想显示图片,并让配置返回403

1 个答案:

答案 0 :(得分:0)

每个位置都应有明确的动作。

在〜regexp匹配位置上,长路径将首先匹配。

server {
    listen 80;

    location / {
        include /etc/nginx/mime.types;
        root /var/www/html/LargerProject;
        index index.php index.html index.htm;
    }

    location ^~ /Discord-OAuth2/static/ {
        include /etc/nginx/mime.types;
        root /var/www/html/LargerProject;
    }

    location ^~ /Discord-OAuth2/ {
        deny all;
    }
}
相关问题