Skip to main content
Topic: CDN Support (Read 2969 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

CDN Support

Is there any plan for supporting CDN?

The free CDNs : CloudFlare and Incapsula.
The paying CDNs : MaxCDN, CloudFront and CDN77.

Or I just misunderstood about how to setup CDN in CMSes (not limited to ElkArte)?

Re: CDN Support

Reply #1
They work a few stages back at the DNS stage, by default, this software will work with ut.

Re: CDN Support

Reply #2
The only issue that I know of with CDN's is that the $_SERVER['REMOTE_ADDR'] will come in as the IP if the CDN for everyone, so that makes IP tracking / banning / geo location etc mostly unusable ...

CloudFlare sends in the original IP in $SERVER['HTTP_CF_CONNECTING_IP'] (but you should not just use that when found, you need to make sure that the REMOTE_ADDR one is from a CloudFlare range)

Will we support that, or is that addon territory?   I'm not sure ... I'm thinking addon as I'd imagine each CDN will have its own IP needs so trying to address that in core would be a source of continual maintenance.
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: CDN Support

Reply #3

@Trekkie101 and @Spuds : Yeah, that is how CloudFlare and Incapsula do their CDN setup, and I failed badly when trying to use them (not on the same time).

When I'm using MaxCDN there is a difference in how to setup, I don't need to change my NS to them. I just need to add one or more CNAME record to them. I found easier that way.

I agree with you @Spuds this is addon material, because not everyone will use CDN. But I believe for the free ones (CloudFlare and Incapsula) many would request them in the future.

Thanks for hearing me out.

Re: CDN Support

Reply #4
There are more issues with CDN'S if the real IP is not properly passed through the server or CDN:

Session: Users will always get: s"ession expired".
Attachements: Upload due to session problem impossible (same error message)
Search: by Google PSS search is messed up and throws error 414: URL is too long (due to given parameters)

Quick and dirty solution:
add the following to index.php:
Code: [Select]
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];

Search: only solution to set the search to subdomain which is not delivered by CDN.

Re: CDN Support

Reply #5
 emanuele tracks this to remember to check if there is a way to hook and change what is necessary without having to touch the code.
Bugs creator.
Features destroyer.
Template killer.

Re: CDN Support

Reply #6
I am extending the discussion about CDN since the topic is already opened in here. Basically in EU Cookie Notification thread, I mentioned about testing this two months ago.  ;)

I was basically thinking if all EA updated (default) js and css can be put into a CDN like what was used by Insites Cookie Consent which is basically using a combination from their github at https://github.com/cdnjs/cdnjs and call them via cloudflare via this code:
Code: [Select]
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
My testing was different however, in the sense that I were creating https://cdn.sch.my where all images, js and css files for https://elkarte.sch.my were supposedly kept but actually in the same path but only using different domain name. My test went missing but I think recreating them is not that difficult since I was just using the repair_settings.php to do all that replacement together with multi-tenancy addon.[1]

At the end, I am not sure why I was doing all these at the first place but may be I'll recall them when I started to do it again.  :D
I think there could be minor changes which I might have forgotten. O:-)

Re: CDN Support

Reply #7
The only issue that I know of with CDN's is that the $_SERVER['REMOTE_ADDR'] will come in as the IP if the CDN for everyone, so that makes IP tracking / banning / geo location etc mostly unusable ...

CloudFlare sends in the original IP in $SERVER['HTTP_CF_CONNECTING_IP'] (but you should not just use that when found, you need to make sure that the REMOTE_ADDR one is from a CloudFlare range)

Will we support that, or is that addon territory?   I'm not sure ... I'm thinking addon as I'd imagine each CDN will have its own IP needs so trying to address that in core would be a source of continual maintenance.
If the various CDN always use the $SERVER variable, we could just add a setting to specify the index holding the IP that we should use.
The only part I'm not sure about, is if having it in $modSettings is early enough to deal with out internals or we need to know the index before that.
Bugs creator.
Features destroyer.
Template killer.

Re: CDN Support

Reply #8
It is being tracked for years. Hopefully, this could be resolved / added as features.

Re: CDN Support

Reply #9
Well, my proposal stands only if the condition is valid. Now someone has to verify it. xD
Bugs creator.
Features destroyer.
Template killer.

Re: CDN Support

Reply #10
I'm not sure if all of the services send the original IP in the connection.

Doing some more looking, Cloudflare and Incapsula set $_SERVER['HTTP_X_FORWARDED_FOR'] which seems to be the industry standard for these services.  So a simple setting to enable CDN may be simply along the lines of.
Code: [Select]
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}

That is somewhat unique to CDN's where you change your DNS to point to them and they choose the assets.  If you are using, I'll say traditional CDN, such as cloudfront (amazon) then its not a problem since you are simply pointing certain assets (js/css/etc) to be fetched from the CDN URL. 

For a traditional setup we would need the ability to point JS, CSS, Theme assests (images), avatars, and maybe attachment URL's, for the borg cloud style CDN simply a check the HTTP_X_FORWARDED_FOR header maybe all that is needed.
Squish squish. squish, squish, squish.
Find a bug,
Make a wish.

Re: CDN Support

Reply #11
Haha... I cannot verify anything regarding this. I don't even know how it is done to to be done properly.

Re: CDN Support

Reply #12
Nothing to verify, my proposal doesn't work because the request cleaning comes before having modSettings populated, so it is too early.
Bugs creator.
Features destroyer.
Template killer.

 

Re: CDN Support

Reply #14
Still I do not understand this CDN that much. But as said:
I was basically thinking if all EA updated (default) js and css can be put into a CDN like what was used by Insites Cookie Consent which is basically using a combination from their github at https://github.com/cdnjs/cdnjs and call them via cloudflare via this code:
Code: [Select]
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
I was thinking if we are to test this cdn idea, we could participate and create a branch of elkarte default static files in there?

Just a thought...