How to use Virtual Private Server as Wordpress Image CDN

I have 2 Private Server and 1 Shared hosting. 1 of my private server is not much in use, but my shared hosting is getting overloaded with images running wordpress.

I want to set my own CDN with my private server. I have already done below things :-

  1. Create CDN subdomain of my site ( http://cdn.example.com with CNAME of my private server. )
  2. Added CDN subdomain to my Private Server ( http://cdn.example.com )

I need help in below two things :-

  1. Whenever image is uploaded , it instantly gets uploaded to my CDN server, that i have created in my VPS.
  2. All images starts loading from my CDN server like :- http://cdn.example.com/wp-content/uploads/2015/10/1.jpg

For 2, I think, There is option to use ".htaccess" , but I am too much worried about point 1, how to make wordpress upload my file to CDN instead of local folder.

Please do not comment and reply with , Use CDN company like maxcdn etc., I can't afford to pay 1 extra cent to CDN at the moment.

I need solution strictly based on my requirement above.

Any help would be highly appreciated.

Thanks

Topic vps cdn plugins Wordpress optimization

Category Web


It sounds you want to do something similar as described in this article https://surpriseazwebservices.com/serve-images-from-sub-domain-in-wordpress/. You'll need to define your upload_url_path as your private server and also update the path of your existing images by running the following query in MySQL.

UPDATE wp_posts SET post_content = REPLACE (post_content,'http://yoursite.com/wp-content/uploads/','http://img.yoursite.com/'); 

The steps should all be documented in the link.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.