1

安全なリンクを書き直そうとしています。ここに私のnginx confがあります:

    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";
    }

次のようにダウンロードリンクを配置すると、その作業が行われます。

http://13.37.13.37/auth/path/to/dir/file.zip?h=sdiouqosid&e=1337&f=the_file.zip

しかし、次のようにリンクを印刷するとそうではありません:

http://subdir.mysite.org/auth/path/to/dir/file.zip?h=sdiouqosid&e=1337&f=the_file.zip

ご注意ください:

  • subdir.mysite.org の DNS レコードには、13.37.13.37 への「A」リダイレクトがあります。
  • 13.37.13.37 は mysite.org とは異なるサーバーです

また:
- http://subdir.mysite.org/path/to/something/somefile.zipはうまく機能します。失敗するのは secure_link を使用した場合のみです (403 を返すか、リソースの読み込みに失敗します)。私のurl_rewriteと関係があると思います。この奇妙な動作に関して、私は多くのことを試しましたが、成功しませんでした。

ご協力ありがとうございました

編集:
以下の完全なnginx:

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";
        }


    }

}
4

2 に答える 2

0

「リバース」(ホスト名)を編集する際の問題を解決しました。
よろしく、

于 2013-07-18T17:40:19.080 に答える
0

/filesすべてを拒否するだけなので、今のところ 403 を返すのは理にかなっているからです。

location /files/ {
    internal;
}

これは、403 の代わりに許可されていない場合に 404 を返します。それが機能するかどうかはわかりません。

于 2013-07-16T18:58:26.750 に答える