首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx重写安全链接

nginx重写安全链接
EN

Stack Overflow用户
提问于 2013-07-16 15:17:25
回答 2查看 2.9K关注 0票数 1

我正在尝试重写一个安全链接,这里是我的nginx conf:

代码语言:javascript
复制
    location /files/ {
        deny all;
        return 403;
    }

    # MEMBERS ONLY #####
    location /auth/ {
        secure_link $arg_h,$arg_e;
        secure_link_md5 authkey$uri$arg_e;
        if ($secure_link = "") {
            return 403;
        }
        if ($secure_link = "0") {
            return 403;
        }
        rewrite  ^/auth/(.*)$  /files/$1  break;
        add_header Content-Disposition "attachment; filename=$arg_f";
    }

如果我像这样放置下载链接,它的工作是:

代码语言:javascript
复制
http://13.37.13.37/auth/path/to/dir/file.zip?h=sdiouqosid&e=1337&f=the_file.zip

但如果我像这样打印链接,它就不会了:

代码语言:javascript
复制
http://subdir.mysite.org/auth/path/to/dir/file.zip?h=sdiouqosid&e=1337&f=the_file.zip

请注意:

  • subdir.mysite.org记录中的"A“值为13.37.13.37
  • 13.37.13.37与mysite.org不同的服务器

另外:

  • http://subdir.mysite.org/path/to/something/somefile.zip工作得很好,只有当我使用secure_link时,它才会失败(返回403或失败加载重新源)。我想这和我的url_rewrite有关。对于这种奇怪的行为,我做了很多尝试,但都没有成功。

谢谢你的帮助

编辑:

完整的nginx如下:

代码语言:javascript
复制
user www-data;
worker_processes  2;

events {
    worker_connections  1024;
}

http {

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    #server_tokens off;

    keepalive_timeout  65;

    gzip on;
    gzip_disable "msie6";

    limit_conn_zone $binary_remote_addr zone=freeuser:10m;

    map $request_uri $request_qs {
        default '';
        ~.*\?(?P<key>.+)$ $key;
    }

    server {

        listen          80;
        server_name     localhost;
        root            /var/www;


        location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            access_log off;
            add_header Cache-Control public;
        }


        location ~* \.(jpg|jpeg|gif|css|png|js|ico|swf|mp3)$ {
            expires        365d;
            access_log     off;
        }


        location /file/ {
            deny all;
            return 403;
           }


        location /auth/ {
            secure_link $arg_h,$arg_e;
            secure_link_md5 authkey$uri$arg_e$remote_addr;
            if ($secure_link = "") {
                return 403;
            }
            if ($secure_link = "0") {
                return 403;
            }
            rewrite  ^/auth/(.*)$  /file/$1  break;
            add_header Content-Disposition "attachment; filename=$arg_f";
        }


    }

}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-18 17:40:19

我解决了编辑“反向”(主机名)的问题。

致以敬意,

票数 0
EN

Stack Overflow用户

发布于 2013-07-16 18:58:26

我会说更改/files块,因为现在返回403是合乎逻辑的,因为您只是拒绝所有。

代码语言:javascript
复制
location /files/ {
    internal;
}

这将返回404的非授权,而不是403,不知道这是否适用于你。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17680553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档