Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ohhdemgirls/14390c13cfaf019e049f7e59049421a2 to your computer and use it in GitHub Desktop.
Save ohhdemgirls/14390c13cfaf019e049f7e59049421a2 to your computer and use it in GitHub Desktop.

Revisions

  1. @userqq userqq revised this gist May 9, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion google drive reverse proxy nginx.conf
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # . '/' . 'internal_google_drive'
    # . '/' . $google_drive_file_id
    # . '/' . $filename
    # . '/' . $google_drive_access_tonel;
    # . '/' . $google_drive_access_token;
    # http_response_code(204);
    # header('X-Accel-Redirect: ' . rawurlencode($accelUri));
    #
  2. @userqq userqq revised this gist May 9, 2019. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions google drive reverse proxy nginx.conf
    Original file line number Diff line number Diff line change
    @@ -33,13 +33,7 @@ location ~* ^/internal_google_drive/(.+)/(.+)/(.*)$ {
    # Compose download url
    set $download_url https://www.googleapis.com/drive/v3/files/$download_id?alt=media;

    #add_header X-A "$download_url";
    #add_header X-Token 'Bearer $token';
    #add_header X-Auth $sent_http_authorization;

    # Set download request headers
    #proxy_set_header Host $download_host;
    #proxy_set_header Authorization '';
    proxy_set_header Authorization 'Bearer $token';

    # The next two lines could be used if your storage
  3. @userqq userqq revised this gist May 9, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions google drive reverse proxy nginx.conf
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,8 @@
    #
    # $accelUri = ''
    # . '/' . 'internal_google_drive'
    # . '/' . $session['download']['drive_file_id']
    # . '/' . $session['download']['filename']
    # . '/' . $google_drive_file_id
    # . '/' . $filename
    # . '/' . $google_drive_access_tonel;
    # http_response_code(204);
    # header('X-Accel-Redirect: ' . rawurlencode($accelUri));
  4. @userqq userqq revised this gist May 9, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions google drive reverse proxy nginx.conf
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # . '/' . 'internal_google_drive'
    # . '/' . $session['download']['drive_file_id']
    # . '/' . $session['download']['filename']
    # . '/' . $this->getToken();
    # . '/' . $google_drive_access_tonel;
    # http_response_code(204);
    # header('X-Accel-Redirect: ' . rawurlencode($accelUri));
    #
    @@ -63,4 +63,4 @@ location @dispose {
    proxy_method GET;
    proxy_set_header Host $server_name;
    proxy_pass $path;
    }
    }
  5. @userqq userqq created this gist May 9, 2019.
    66 changes: 66 additions & 0 deletions google drive reverse proxy nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    # # # # # # # # # #
    # USAGE:
    #
    # $accelUri = ''
    # . '/' . 'internal_google_drive'
    # . '/' . $session['download']['drive_file_id']
    # . '/' . $session['download']['filename']
    # . '/' . $this->getToken();
    # http_response_code(204);
    # header('X-Accel-Redirect: ' . rawurlencode($accelUri));
    #
    # # # # # # # # # #

    location ~* ^/internal_google_drive/(.+)/(.+)/(.*)$ {
    limit_rate 1m;

    # Do not allow people to mess with this location directly
    # Only internal redirects are allowed
    internal;

    # nginx has to be able to resolve the remote URLs
    resolver 8.8.8.8;

    # Location-specific logging
    access_log /var/log/nginx/internal_google_drive.access.log;
    error_log /var/log/nginx/internal_google_drive.error.log;

    # Extract download url from the request
    set $download_id $1;
    set $filename $2;
    set $token $3;

    # Compose download url
    set $download_url https://www.googleapis.com/drive/v3/files/$download_id?alt=media;

    #add_header X-A "$download_url";
    #add_header X-Token 'Bearer $token';
    #add_header X-Auth $sent_http_authorization;

    # Set download request headers
    #proxy_set_header Host $download_host;
    #proxy_set_header Authorization '';
    proxy_set_header Authorization 'Bearer $token';

    # The next two lines could be used if your storage
    # backend does not support Content-Disposition
    # headers used to specify file name browsers use
    # when save content to the disk
    proxy_hide_header Content-Disposition;
    add_header Content-Disposition 'attachment; filename="$filename"';

    # Do not touch local disks when proxying
    # content to clients
    proxy_max_temp_file_size 0;

    # Download the file and send it to client
    proxy_pass $download_url;
    post_action @dispose;
    }

    location @dispose {
    set $path https://127.0.0.1/dl/dispose;
    proxy_method GET;
    proxy_set_header Host $server_name;
    proxy_pass $path;
    }