nginx - 如何允许图像但拒绝其他一切?
问题描述
文件结构为
- 更大的项目
- Discord-OAuth2
- config <--不希望任何人访问它
- 静态 <-- 这里的图片
- Discord-OAuth2
当我不包括底部 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
解决方案
每个位置都应该有明确的动作。
在 ~ 正则表达式匹配位置上,较长的路径将首先匹配。
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;
}
}
推荐阅读
- android - GoogleSignIn 统一包依赖冲突 Google Play 服务
- java - 导入 Java BigInteger
- r - 使用长数据格式更改 ggplot2 图中的一种线型
- css - 仅发布压缩 (.min.css) 文件的 Visual Studio 设置
- php - 如何在具有相同键的 1 个数组上使用 array_merge_recursive
- javascript - arr.splice() 方法删除反应原生项目中的错误项目
- hyperlink - 将动态链接添加到自定义字段
- python - 如何将 google colab 中的集群文件保存到 Google Drive
- reactjs - chartjs:条形小于实际列,工具提示不显示
- python - pyspark comapre 仅来自时间戳的时间