Discover Centmin Mod today
Register Now

Xenforo XenForo 2.1 CDN using Cloudflare free plan :D

Discussion in 'Forum software usage' started by rdan, Oct 7, 2019.

  1. rdan

    rdan Well-Known Member

    5,426
    1,389
    113
    May 25, 2014
    Ratings:
    +2,172
    Local Time:
    12:19 AM
    Mainline
    10.2
    Free and not using Cloudflare on main Domain.
    Just to save bandwidth and accelerate static files.

    Code:
    server {
        listen 443 ssl http2;
        server_name cdn.xf.com;
        include /usr/local/nginx/conf/ssl/xf.com_ssl.conf;
    
        access_log off;
        log_not_found off;
        error_log /home/nginx/domains/xf.com/cdn_error.log error;
        root /home/nginx/domains/xf.com/public;
    
        location /               { deny all; }
        location ~ \.(default|html|php|txt|xml)$ { deny all; }
       
        location /data/          { }
        location /js/            { }
        location /styles/        { }
        location ~ ^/(proxy.php) { include /usr/local/nginx/conf/php.conf; }
    
        include /usr/local/nginx/conf/staticfiles.conf;  
    }


     
  2. pdinh97qng

    pdinh97qng Member

    120
    15
    18
    Jan 24, 2016
    Ratings:
    +38
    Local Time:
    8:19 AM
    If I'm not wrong, CloudFlare doesn't allow customer to serve only static files. I saw an email for this situation before:p Better to not violate the rules :yawn:
     
  3. eva2000

    eva2000 Administrator Staff Member

    50,928
    11,808
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,267
    Local Time:
    2:19 AM
    Nginx 1.25.x
    MariaDB 10.x
    I believe @rdan is setting up non-cloudflare protected domain.com hostname that serves static files directly from a separate cloudflare protected cdn.domain.com hostname on Centmin Mod Nginx origin web server. Basically disabling cloudflare orange cloud on domain.com DNS record and enabling cloudflare orange cloud on cdn.domain.com DNS record.

    Yeah they do have such a rule though it's open for interpretation and with their release of Cloudflare Workers, it is all about serving static files :) Cloudflare will contact you if you overstep their usage policy. So you can ask them if unsure.
     
  4. rdan

    rdan Well-Known Member

    5,426
    1,389
    113
    May 25, 2014
    Ratings:
    +2,172
    Local Time:
    12:19 AM
    Mainline
    10.2
    My fully working and updated config.

    Code:
    server {
        listen 80;
        server_name cdn.domain.com;
        return 301 https://cdn.domain.com$request_uri;
    }
    
    server {
        listen 443 ssl http2;
        server_name cdn.domain.com;
        include /usr/local/nginx/conf/ssl/domain.com/domain.com_ssl.conf;
    
        access_log off;
        log_not_found off;
        error_log /home/nginx/domains/domain.com/cdn_error.log error;
        root /home/nginx/domains/domain.com/public;
    
        location /                                { deny all; }
        location ~* \.(default|html|php|txt|xml)$ { deny all; }
    
        location ~* \.(gif|jpg|jpe|jpeg|png|ico)$ {
        gzip_static off;
        add_header Link "<https://domain.com$request_uri>; rel=\"canonical\"";
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
        expires 30d;
        break;
        }
    
        location ~* \.(3gp|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|br)$ {
        gzip_static off;
        sendfile off;
        sendfile_max_chunk 1m;
        add_header Link "<https://domain.com$request_uri>; rel=\"canonical\"";
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
        expires 30d;
        break;
        }
    
        location ~* \.(js|json)$ {
        add_header Link "<https://domain.com$request_uri>; rel=\"canonical\"";
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
        expires 30d;
        break;
        }
    
        location ~* \.(css)$ {
        add_header Link "<https://domain.com$request_uri>; rel=\"canonical\"";
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
        expires 30d;
        break;
        }
    
        location ~* \.(eot|svg|ttf|woff|woff2|less|otf|scss)$ {
        add_header Link "<https://domain.com$request_uri>; rel=\"canonical\"";
        add_header Access-Control-Allow-Origin *;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        expires 365d;
        break;
        }
    
    
    }
    
     
  5. pdinh97qng

    pdinh97qng Member

    120
    15
    18
    Jan 24, 2016
    Ratings:
    +38
    Local Time:
    8:19 AM
    @rdan can you share your page rules :nailbiting:
     
  6. rdan

    rdan Well-Known Member

    5,426
    1,389
    113
    May 25, 2014
    Ratings:
    +2,172
    Local Time:
    12:19 AM
    Mainline
    10.2
    Why :nailbiting:? :D

    Just basic Cache Everything option.
    upload_2019-10-10_3-20-41.png
     
  7. eva2000

    eva2000 Administrator Staff Member

    50,928
    11,808
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,267
    Local Time:
    2:19 AM
    Nginx 1.25.x
    MariaDB 10.x
    looks good with canonical headers properly in place too :)
     
  8. negative

    negative Active Member

    415
    50
    28
    Apr 11, 2015
    Ratings:
    +98
    Local Time:
    6:19 PM
    1.9.10
    10.1.11
    Do you advice that add the canonical header even without using the cloudflare as CDN in free plan ?
     
  9. eva2000

    eva2000 Administrator Staff Member

    50,928
    11,808
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,267
    Local Time:
    2:19 AM
    Nginx 1.25.x
    MariaDB 10.x
    yeah doesn't hurt
     
  10. negative

    negative Active Member

    415
    50
    28
    Apr 11, 2015
    Ratings:
    +98
    Local Time:
    6:19 PM
    1.9.10
    10.1.11
    is it enough put that code to location / in my host conf ?
    Code:
    add_header Link "<https://domain.com$request_uri>; rel=\"canonical\"";
     
  11. rdan

    rdan Well-Known Member

    5,426
    1,389
    113
    May 25, 2014
    Ratings:
    +2,172
    Local Time:
    12:19 AM
    Mainline
    10.2
    Maybe, but static files won't have that header.

    After 1 month :)
    upload_2019-11-15_22-30-19.png
     
  12. eva2000

    eva2000 Administrator Staff Member

    50,928
    11,808
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,267
    Local Time:
    2:19 AM
    Nginx 1.25.x
    MariaDB 10.x
    excellent results there :)
     
  13. JJC84

    JJC84 Ad astra per aspera

    247
    109
    43
    Jan 31, 2018
    San Antonio, Texas
    Ratings:
    +169
    Local Time:
    10:19 AM
    1.15.x
    10.x.x
    I have to say this is an exemplary config! Thank you for sharing this @rdan it has helped me in squeezing a bit more performance.

    Because... performance matters right!
     
  14. upgrade81

    upgrade81 Member

    290
    17
    18
    Sep 5, 2016
    CH
    Ratings:
    +30
    Local Time:
    5:19 PM
    1.17
    10.3

    Hi, can I know how you configured static and image files on Xen to point to the Cdn subdomain?

    That is, I miss the step before configuring the vhost relative to the cdn ...
    How do you PULL towards subdomain, that's it.
     
  15. upgrade81

    upgrade81 Member

    290
    17
    18
    Sep 5, 2016
    CH
    Ratings:
    +30
    Local Time:
    5:19 PM
    1.17
    10.3
    Hi, sorry.
    What did you use to tell XenForo to rewrite all urls pointing to various static images or files?

    Thanks
     
  16. rdan

    rdan Well-Known Member

    5,426
    1,389
    113
    May 25, 2014
    Ratings:
    +2,172
    Local Time:
    12:19 AM
    Mainline
    10.2
  17. rdan

    rdan Well-Known Member

    5,426
    1,389
    113
    May 25, 2014
    Ratings:
    +2,172
    Local Time:
    12:19 AM
    Mainline
    10.2
  18. upgrade81

    upgrade81 Member

    290
    17
    18
    Sep 5, 2016
    CH
    Ratings:
    +30
    Local Time:
    5:19 PM
    1.17
    10.3
    Hi, thanks for the answers.

    and to move / synchronize files physically in the subdomain which is enabled on cloudflare?
     
  19. rdan

    rdan Well-Known Member

    5,426
    1,389
    113
    May 25, 2014
    Ratings:
    +2,172
    Local Time:
    12:19 AM
    Mainline
    10.2
    No need to move files, just point the nginx config to the same directory as your main domain.
     
  20. upgrade81

    upgrade81 Member

    290
    17
    18
    Sep 5, 2016
    CH
    Ratings:
    +30
    Local Time:
    5:19 PM
    1.17
    10.3
    ingenious solution!
    Thank you very much