AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-12548

Ahsan's questions

Martin Hope
Ahsan
Asked: 2009-07-27 21:13:27 +0800 CST

在 nginx 和 HTTP-Authentication 下服务静态文件

  • 5

我在服务器上以测试模式部署了一个应用程序。通过 HTTP 身份验证,对它的访问仅限于选定的用户组。这很好用。问题是,如果我通过不同的“位置”指令提供静态文件,nginx 会为这些文件提供“未授权”。我尝试关闭 auth_basic,但没有骰子。

这是虚拟主机配置:

# Virtual Host 

upstream appname {
  server 127.0.0.1:4000;
  server 127.0.0.1:4001;
  server 127.0.0.1:4002;
}

server { 
  listen 80;
  server_name appname.domain.com;

  # write app specific log
  # make sure you create this file in your log directory before running behind nginx
  access_log  /home/apps/appname/shared/log/nginx.log  main;

 # let nginx serve static files directly
  # images
  location ^~/images {
    auth_basic off;
    root /home/apps/appname/current/public/images;

  }

  location ^~/covers {
    auth_basic off;
    root /home/apps/covers;

  }

 # # javascript
 location ^~/javascripts {
    auth_basic off;
   root /home/apps/appname/current/public/javascripts;
 }

 # # css
  location ^~/stylesheets {
   auth_basic off;
    root /home/apps/appname/current/public/style;
 }           

  # Push all other requests to Merb
  location / {
    # needed to forward user's IP address to merb
    proxy_set_header  X-Real-IP  $remote_addr;

    auth_basic "domains";
    auth_basic_user_file htpasswd;

    if (!-f $request_filename) {
      proxy_pass http://appname;
      break;
    }
  }

}

有什么建议么 ?

编辑:

我尝试将图像放在另一个子域下并为其配置单独的“服务器”块 - 没有任何 http_auth。但它仍然在图像上给了我一个 403 禁止!这是我添加的内容:

server {
  listen 80;
  server_name images.domain.com;

  access_log  /home/apps/appname/shared/log/nginx_images.log  main;
  error_log  /home/apps/appname/shared/log/nginx_images_error.log;

  error_page 500 502 503 504  /500.html;
  location = /500.html {
    root  /home/apps/www/http_error_codes;
  }

 location /images {
   root /home/apps/appname/current/public/images;
 }

 location /covers {
   root /home/apps/covers;
 }

 open_file_cache max=1000 inactive=20s;
 open_file_cache_valid    30s;
 open_file_cache_min_uses 2;
 open_file_cache_errors   on;
}

我还尝试打开一个新浏览器并直接从 images.domain.com 访问图像文件,但它仍然显示 403 禁止!

authentication configuration nginx http-basic-authentication
  • 2 个回答
  • 13523 Views
Martin Hope
Ahsan
Asked: 2009-07-12 20:18:32 +0800 CST

提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 5

我需要使用 nginx 提供大约 70,000 个静态文件 (jpg)。我应该将它们全部转储到一个目录中,还是有更好(有效)的方法?由于文件名是数字,我考虑有一个目录结构,如:

xxx/xxxx/xxx

操作系统为 CentOS 5.1

performance web-server nginx static-content
  • 12 个回答
  • 1785 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve