Jump to content

Setting up Media Servers, keep images on both locations or not?


Recommended Posts

Hi,

 

I want to use a new VPS as media server to put my static content on.

the problem was I had too many image files on my shared hosting on bluehost (700,000+ images, including thumbnails etc)

So as a result, I have to delete the images after I've copied them to the new server,

but in the Prestashop wiki it is said that:

 

"Reminder: you must make it so that these folders are always synchronized."

 

So, do I have to keep the images on my shared hosting as well? or I can simply move them to the new VPS?

 

Any piece of info or advice is highly appreciated :)

Link to comment
Share on other sites

if you are trying to use media servers, then you need to keep the original files on the prestashop installation server. These act as the primary source, from which the CDN's pull their cache from.

 

Keep in mind that CDN's are only used for the front end, customer facing portion of the website. So if you remove the images from the local prestashop installation folders, then your back office will not show these images. Also, when you add new products, those images will be installed in the base /img folder, and then you would have to copy them over to your VPS server

 

now you could try to create subdomains, like

media1.domain.com

media2.domain.com

media3.domain.com

 

and have these subdomains pointing to your VPS server, where you would have the static cache of the css, js and images.

 

I thought I saw blogs showing exactly how to accomplish this, you should try a google search to see if you can find it.

  • Like 1
Link to comment
Share on other sites

Thanks for the info!

I think I have to forget about the images on backoffice for now, because if I do not delete all those 700,000 images from my shared hosting they'd deactivate my account for using too much server resources!

Link to comment
Share on other sites

Also I have another question, I've tried using media server, copied the /img folder on the VPS and created an redirected the subdomain, however the images won't load, because it looking for the image in this link:

 

http://media1.mysite.com/19609-rect_default/image-name.jpg

 

that is a Friendly URL, but of course the real image is in:

 

http://<that servers IP address>/img/1/5/2/3/image-name.jpg

 

the subdomain will redirect successfully to the VPS IP address and it'll be like:

 

http://<that servers IP address>/19609-rect_default/image-name.jpg

 

which is obviously not true.

 

Disabling Friendly URLs in BO will do the job but I don't really look forward to disabling friendly URLs.

 

Anyone has and idea how to work around this?

  • Like 1
Link to comment
Share on other sites

Thanks for info.

The VPS uses windows 2008 server so I couldn't use htaccess on there, instead I tried to convert the link before they are sent to the VPS by putting an htaccess in the subdirectory of the subdomain, it got me a few tries but finally it worked fine.

Link to comment
Share on other sites

  • 10 months later...
  On 5/3/2013 at 10:43 AM, danx88 said:

Thanks for info.

The VPS uses windows 2008 server so I couldn't use htaccess on there, instead I tried to convert the link before they are sent to the VPS by putting an htaccess in the subdirectory of the subdomain, it got me a few tries but finally it worked fine.

 

It will be helpfull for me if you can explain how did you do this!!!

 

Thanks!

Link to comment
Share on other sites

  • 1 month later...
  On 5/2/2013 at 5:27 PM, danx88 said:

Also I have another question, I've tried using media server, copied the /img folder on the VPS and created an redirected the subdomain, however the images won't load, because it looking for the image in this link:

 

http://media1.mysite.com/19609-rect_default/image-name.jpg

 

that is a Friendly URL, but of course the real image is in:

 

 

 

the subdomain will redirect successfully to the VPS IP address and it'll be like:

 

<that servers IP address>/19609-rect_default/image-name.jpg

 

which is obviously not true.

 

Disabling Friendly URLs in BO will do the job but I don't really look forward to disabling friendly URLs.

Anyone has and idea how to work around this?

 

Hi Anyone found a workaround for this.

I've setup a cdn to load images faster, but it works with full url, not with rewritten url

Edited by sennevb (see edit history)
Link to comment
Share on other sites

  • 5 months later...
  On 5/10/2014 at 12:19 PM, sennevb said:

 

Hi Anyone found a workaround for this.

I've setup a cdn to load images faster, but it works with full url, not with rewritten

I copied the .htacces from the root of the BO server to the CDN server and changed all the references from img/ to /

Works great now!

  • Like 1
Link to comment
Share on other sites

  On 10/24/2014 at 6:13 PM, sjaakie3 said:

I copied the .htacces from the root of the BO server to the CDN server and changed all the references from img/ to /

Works great now!

 

Hi, 

 

what do you mean with the changes references, did you change this code in htaccess for example for the same without "img"?

RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  On 10/24/2014 at 6:13 PM, sjaakie3 said:

I copied the .htacces from the root of the BO server to the CDN server and changed all the references from img/ to /

Works great now!

 

Hi, can you please elaborate more on this. Perhaps you can share an exerpt of your htaccess with us here..

  • Like 1
Link to comment
Share on other sites

  • 9 years later...

Hello!

Post seems to be old but still many might be fighting with this issue. I'm having my own servers and datacenter where I run other stuff as well, but for few my webshops I have PS1.7  (will be upgraded soon to 8.2)  and one shop running with  PS8.2.

I have first media server  running as virtualhost on same server than shop itself but with hostname  static-01.mydomain.com ,  all the static content from img folder are just symlinked  <ps_root_>/img  -> <media_server_root>/img  (ln -s <ps_root>/img ../<_media_server_root>/img/)  and so on. 

I have second media server on other location in different country,  there I have just virtualhost for host  static-02.mydomain.com,  I have there own server as well.  I have made crontab task for rsync process which runs every 1 minute on webserver,  I use ssh keys only so no need  to hassle with passwords. 

* *    * * *   root    /usr/bin/rsync -qvaz --size-only --delete -e "ssh -p 22222" /my/sitesfolders/my_ps_root/img   mylogin@mymediaserver.fi:/my/sitesfolders/static-02/img

* *    * * *   root    /usr/bin/rsync -qvaz --size-only --delete -e "ssh -p 22222" /my/sitesfolders/my_ps_root/modules  mylogin@mymediaserver.fi:/my/sitesfolders/static-02/modules

* *    * * *   root    /usr/bin/rsync -qvaz --size-only --delete -e "ssh -p 22222" /my/sitesfolders/my_ps_root/themes   mylogin@mymediaserver.fi:/my/sitesfolders/static-02/themes

This keeps files synced, if you delete some module / products, rsync deletes it also remote located server on next sync. 

(ssh port number is 22 but I have all default stuff always changed if possible) 

I'm having  <ps_root>/img    <ps_root>/modules   <ps_root>/templates  and <ps_root>/themes    synced and linked to static-01 and static-02, I need templates and themes also for my own purposes.

I've created  certificates for these static-01.mydomain.com and static-02.mydomain.com with certbot which will automatically renew  certs when needed. 

NOTE: Cronjob doesnt have to sync every minute but it does not slowdown anything because most likely there's nothing to sync until you add some new products / modules. 

Both static-01 and static-02 I've copied modified version of .htaccess from main website to make images rewriting correct, here's example from my static-01 server.

Here's my .htaccess   please note that you must have that server's domain in htaccess file where it's loaded. 

 

<IfModule mod_rewrite.c>
RewriteEngine On
#Domain: static-01.mydomain.com
RewriteRule . - [E=REWRITEBASE:/]

# JPG ADDED BY MTH 20.1.2024 
RewriteCond %{HTTP_ACCEPT} image/jpg
RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteCond %{DOCUMENT_ROOT}%{ENV:REWRITEBASE}$1.jpg -f
RewriteRule (.+)\.(jpe?g|png)$ %{ENV:REWRITEBASE}$1.jpg [T=image/jpg,L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
#END OF JPG

RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteCond %{DOCUMENT_ROOT}%{ENV:REWRITEBASE}$1.webp -f
RewriteRule (.+)\.(jpe?g|png)$ %{ENV:REWRITEBASE}$1.webp [T=image/webp,L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/c/$1$2$3.webp [L]

RewriteCond %{HTTP_HOST} ^static-01.mydomain.com$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/c/$1$2.webp [L]

</IfModule>

 

Hope this save some time for someone.  

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...