Join the community today
Become a Member

Wordpress woocommerce and x-accel-redirect for downloadable product

Discussion in 'Blogs & CMS usage' started by nikolaikapustin, Oct 5, 2016.

  1. nikolaikapustin

    nikolaikapustin Member

    37
    5
    8
    Oct 5, 2016
    Ratings:
    +7
    Local Time:
    1:41 PM
    Hi guys,

    anyone was success with x-accel-redirect setup? I need to serve some digital product as download. I migrate a shop from apache to nginx (redis cache). With apache and X-sendfile was easy, now i really can't figure out what is wrong with nginx.. i always get ERR_INVALID_RESPONSE.
     
  2. eva2000

    eva2000 Administrator Staff Member

    31,025
    6,927
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,433
    Local Time:
    10:41 PM
    Nginx 1.13.x
    MariaDB 5.5
    Never used woocommerce myself so best to see what others have to say.

    When you create a new nginx vhost domain via centmin.sh menu option 2 or menu option 22 or via /usr/bin/nv cli command line, you will create the Nginx vhost files and directories. You will get an outputted the path location where it will create the domain name's vhost conf file named newdomain.com.conf (and newdomain.com.ssl.conf if you selected yes to self signed SSL)
    • Nginx vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.conf
    • Nginx HTTP/2 SSL vhost conf path will be at /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
    • Nginx Self-Signed SSL Certificate Directory at /usr/local/nginx/conf/ssl/newdomain.com
    • Vhost public web root will be at /home/nginx/domains/newdomain.com/public
    • Vhost log directory will be at /home/nginx/domains/newdomain.com/log
    Please post the contents of /usr/local/nginx/conf/conf.d/newdomain.com.conf and if applicable /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf wrapped in CODE tags (outlined at How to use forum BBCODE code tags)
     
  3. nikolaikapustin

    nikolaikapustin Member

    37
    5
    8
    Oct 5, 2016
    Ratings:
    +7
    Local Time:
    1:41 PM
    I partially solved removing
    Code (Text):
    location ~* ^/(wp-content)/(.*?)\.([B]zip[/B]|gz|tar|bzip2|7z)$ { deny all; }
    from wpsecure_domain.com.conf
    X-Accel-Redirect is now serving the downloads but the woocommerce path /wp-content/uploads/woocommerce_uploads/ is now free to everyone and not protected anymore.
    It seems that woocommerce php code is not really redirecting the downloads...
    I read some needed tweak on domain.com.conf
    Code (Text):
    location /protected/ {
     internal;
     root   /some/path/wp-content/uploads/woocommerce_uploads;
    }
    but at this point you need to hard code woocommerce plugin. Can't be the solution.
    Anyone faced it?
     
  4. nikolaikapustin

    nikolaikapustin Member

    37
    5
    8
    Oct 5, 2016
    Ratings:
    +7
    Local Time:
    1:41 PM
    Solved. Now X-Accel-Redirect serves the downloads with nginx (redis cache) and the original files path is safely protected.
    I modified this line in wpsecure_domain.com.conf
    Code (Text):
    location ~* ^/(wp-content)/(.*?)\.(gz|tar|bzip2|7z)$ { deny all; }
    removing zip extension because my digital goods are mainly zipped archives.
    Then i added a new location (it can be placed in wpsecure too), the instruction "internal" gives 404 error to unwanted requests from outside, not "alias" needed since woocommerce php code will manage it.
    Code (Text):
    location ~* /wp-content/uploads/woocommerce_uploads/ {
    internal;
        include /usr/local/nginx/conf/php-rediscache.conf;
    }
    and nginx is really faster than apache with X-Sendfile. ;)
     
    • Informative Informative x 1
  5. eva2000

    eva2000 Administrator Staff Member

    31,025
    6,927
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,433
    Local Time:
    10:41 PM
    Nginx 1.13.x
    MariaDB 5.5
    nice. you maybe able to keep zip in wpsecure if your woocommerce uploads directory location context is modified slightly

    Code (Text):
    location ~* /wp-content/uploads/woocommerce_uploads/ {
      internal;
      location ~* ^/wp-content/uploads/woocommerce_uploads/(.+/)?(.+)\.(zip)$ { allow all; }
      include /usr/local/nginx/conf/php-rediscache.conf;
    }
    
     
  6. nikolaikapustin

    nikolaikapustin Member

    37
    5
    8
    Oct 5, 2016
    Ratings:
    +7
    Local Time:
    1:41 PM
    Unfortunately placing back "zip" in wpsecure and using that setup for location i'm getting ERR_INVALID_RESPONSE. :banghead:
     
  7. eva2000

    eva2000 Administrator Staff Member

    31,025
    6,927
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,433
    Local Time:
    10:41 PM
    Nginx 1.13.x
    MariaDB 5.5
    oh well