Want more timely Centmin Mod News Updates?
Become a Member

Nginx Nginx directory to CDN rewrite

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Amin Sabet, Dec 13, 2016.

  1. Amin Sabet

    Amin Sabet Member

    47
    6
    8
    Nov 8, 2015
    Ratings:
    +13
    Local Time:
    8:28 PM
    Is there any way to use Nginx to rewrite my XenForo attachments to CDN?

    I woud like guests to get

    https://cdn.mu-43.com/data/attachments/126/126213-df8ab402dc65b791759f38fcb8fd735a.jpg

    instead of

    https://www.mu-43.com/data/attachments/126/126213-df8ab402dc65b791759f38fcb8fd735a.jpg

    while members get

    https://cdn.mu-43.com/attachments/30372689452_909eaf5039_h-jpg.146005/

    instead of

    https://www.mu-43.com/attachments/30372689452_909eaf5039_h-jpg.146005/

    I can use the Tinhte "Image Attachment Optimization & CDN Support" addon to rewrite attachments to CDN, but it circumvents all attachment permissions, so guests don't get thumbnails even though their permissions are set that way.

    Is something like this possible using Nginx rewrite rules?
     
  2. eva2000

    eva2000 Administrator Staff Member

    28,987
    6,579
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,767
    Local Time:
    10:28 AM
    Nginx 1.13.x
    MariaDB 5.5
    Don't know off the top of my head especially if you want different urls served for guest vs members in xenforo.
     
  3. Amin Sabet

    Amin Sabet Member

    47
    6
    8
    Nov 8, 2015
    Ratings:
    +13
    Local Time:
    8:28 PM
  4. eva2000

    eva2000 Administrator Staff Member

    28,987
    6,579
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,767
    Local Time:
    10:28 AM
    Nginx 1.13.x
    MariaDB 5.5
    probably just use ngx_http_sub_module which is enabled in Centmin Mod Nginx Module ngx_http_sub_module

    i.e. i use it for my centmin.sh mirror for centminmod.com as i want to disable the CDN when served via centmin.sh

    i.e.

    Code (Text):
      sub_filter "url('//sitecdn.centminmod.com/"   "url('//centmin.sh/";
      sub_filter_last_modified on;
      sub_filter_once off;
    
     
    Last edited: Dec 13, 2016
    • Optimistic Optimistic x 1
  5. Amin Sabet

    Amin Sabet Member

    47
    6
    8
    Nov 8, 2015
    Ratings:
    +13
    Local Time:
    8:28 PM
    Thanks, George.
     
  6. Amin Sabet

    Amin Sabet Member

    47
    6
    8
    Nov 8, 2015
    Ratings:
    +13
    Local Time:
    8:28 PM
    Would changing the URL this way affect attachment creation and/or storage location?
     
  7. eva2000

    eva2000 Administrator Staff Member

    28,987
    6,579
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,767
    Local Time:
    10:28 AM
    Nginx 1.13.x
    MariaDB 5.5
    only what's displayed in a page's html code
     
    • Like Like x 1
  8. Amin Sabet

    Amin Sabet Member

    47
    6
    8
    Nov 8, 2015
    Ratings:
    +13
    Local Time:
    8:28 PM
    Brilliant. I will try it and report back.
     
  9. Amin Sabet

    Amin Sabet Member

    47
    6
    8
    Nov 8, 2015
    Ratings:
    +13
    Local Time:
    8:28 PM
    I just realized that rewriting attachments to CDN makes them not viewable at all even for members when guest permissions are disabled, so probably what I am trying to do isn't possible.
     
  10. eva2000

    eva2000 Administrator Staff Member

    28,987
    6,579
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,767
    Local Time:
    10:28 AM
    Nginx 1.13.x
    MariaDB 5.5
    yeah there's no differential from guests/members