Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to set up a self hosted cdn for my site, but I am having problems with the rules in the htaccess file and I can't get it to work.

At the moment the ftp server that will act as CDN has the following filesystem structure:

/
www/
www/htaccess
www/index.html
www/cdn/*
incremental/*
full/*

My .htaccess looks like this right now:

Options All -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

#This snippet basically stops anyone viewing any file on your site that begins with "hta", this will protect it and make it somewhat safer.
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>

<Files /cdn>
   Options +Indexes
   Satisfy Any
   Allow from all
</Files>

I want to allow access to the cdn folder and disallow any other access to the other folders, because in incremental and full there are backups of my main server.

I've been searching for rules for achieve this behaviour but nothing work.

I have to allow Indexes in the cdn folder?

Regards and thank you in advance (And sorry for my english)

share|improve this question
1  
Put an .htaccess in your other two folders and just have deny from all in it. Your backups should never be web-accessible to begin with, though... –  Nathan C Jul 10 '13 at 22:00
    
Thanks, where do you recomend me to put my backups?, currently I think they are not accesible because there aren't in the www folder. The main server perform a incremental backup every day and send it to the ftp server. –  algui91 Jul 10 '13 at 22:16
    
As long as they can't be browsed to or accessed by a random user you're fine. –  Nathan C Jul 10 '13 at 22:53
    
Then I think all is fine. Now I have a www folder with only two files, index.html and .htaccess with Options -Indexes Order Deny,Allow Deny from All Allow from <ip from my server>, and in the root I have my backups and the same .htaccess. Is now correctly configured to mantain my backups secured? –  algui91 Jul 10 '13 at 22:56
    
This is not a CDN... –  ceejayoz Jul 12 '13 at 14:41

1 Answer 1

Not to be a jerk but this doesn't sound at all like you're building a CDN. The whole concept of a CDN hinges on delivering your users content from a node closest to them vs. your users having to trudge through the internet to a single box.

It's possible in your research you're having trouble finding out what to do because you're adding this "CDN" concept when it's really not pertinent.

I'll echo the previous advice of moving your backups out of the web accessible folder!

Given what I believe you're trying to accomplish I'd advise that you setup separate vhosts that point requests for a given FQDN to a folder. This will give you more control over your configuration and ensure that data is only available to certain domains. So you'd add a new file (myconfig.conf, anything really) in your apache2/conf.d directory that looked something like this:

<VirtualHost *:80>
DocumentRoot /mnt/www/DOMAIN_NAME/cdn
ServerName cdn.DOMAIN_NAME
</VirtualHost>

Obviously you can use whatever you want for your document route, the above is just my personal style. Create the directory path /mnt/www/DOMAIN_NAME/cdn replacing the DOMAIN_NAME with whatever you're using. Then anytime you hit cdn.DOMAIN_NAME it will ONLY serve up files in the /mnt/www/DOMAIN_NAME/cdn directory. Obviously this requires some adjustments to DNS to ensure the cdn subdomain of the DOMAIN_NAME used is pointed to this box.

EDIT: Don't forget to restart apache after you add the new .conf file!

Hopefully this helps. Though if a true CDN is what you need, I'd advise you to use a service like s3/cloudfront or Rackspace Cloudfiles rather than a DIY solution. They're VERY affordable options.

share|improve this answer
    
I think the OP is confusing "CDN" with "cookieless domain for static assets". –  ceejayoz Jul 12 '13 at 14:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.