Static site with netlify + Django on the same url - django

Let's assume I own the domain:
foobar.com/
I want to use Netlify for my static pages like
foobar.com/features/
foobar.com/pricing/
foobar.com/imprint/
etc.
But I also have a Django application on a seperate server on AWS that has nothing to do with the static sites served by Netlify.
My Django has urls like
foobar.com/login/
foobar.com/dashboard/
etc.
Is it possible to use Netlify for a few static pages and my Django application for other pages?
I don't know how start or if this is event possible.

It will depend on how your Django apps handle the target, but you could use rewrites on Netlify using the HTTP status code 200 with a redirect rule (rewrite).
If the API supports standard HTTP caching mechanisms like Etags or Last-Modified headers, the responses will even get cached by CDN nodes.
Have DNS set foobar.com to the Netlify site.
Decide the domain for the Django site on AWS. (proxy.foobar.com)
Setup _redirects at the root of the Netlify site to use Proxy (rewrites) on Netlify
/login/* https://proxy.foobar.com/login/:splat 200
/dashboard/* https://proxy.foobar.com/dashboard/:splat 200
Note: This is how you can incrementally switch a site over to Netlify without having to refactor a site all at once.

When you set a DNS record (e.g. an A record), you can point foobar.com to your AWS server or netlify, but not both.
Perhaps you can put the sites on different domains, for example dashboard.foobar.com for your Django site.
You could then configure netlify to redirect foobar.com/dashboard/ to dashboard.foobar.com/dashboard/

No, you can't have a foobar.com point to two different servers. You'll have to use subdomains, e.g.:
static.foobar.com -> DNS entry for Netlify
app.foobar.com -> DNS entry for your Django server
or, what you often see, is:
foobar.com and www.foobar.com -> DNS pointing to your main website (Netlify)
api.foobar.com and app.foobar.com -> DNS pointing to your Django app

Related

Bad Request (400) in django web app in Azure App service while adding Custom Domain

In the Azure app service
my Website is working fine with something.azurewebsites.net with the following code
ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []
But while adding a custom domain, it is showing as Bad Request (400). I think the problem relies on the Allowed host, and the Django app is not allowing my custom domain. I couldn't find a solution or a perfect line of code to resolve this issue.
Have you set up the custom domain in Azure? To do this, you can follow the steps in the Azure documentation:
https://docs.microsoft.com/en-us/azure/app-service/configure-custom-dns-web-site#map-a-custom-dns-name-to-an-azure-web-app
This will involve adding a CNAME record for your custom domain that points to your Azure app's default domain.
ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME'],os.environ['CUSTOM_HOSTNAME']]
CUSTOM_HOSTNAME should be added to the application configuration in azure.
Eg: CUSTOM_HOSTNAME: www.example.com

Multiple netlify static sites served under a single cloudfront domain path

I have multiple netlify static sites that I want to serve in their entirety under a path of a cloudfront domain. However, resources that don't reside at the root of the netlify app are not being served (raise a 404)
i.e.
https://netlify1-abcd123.netlify.app/
/
/page1
/page1/subpage1
/page2
/images/logo.png
/stylesheets/styles.css
https://netlify2-defg456.netlify.app/
/
/netlify2-page1
/netlify2-page1/subpage1
/netlify2-page2
/netlify2-images/logo.png
/netlify2-stylesheets/styles.css
and I want these to be served under www.mydomain.com/netflify1 and www.mydomain.com/netlify2. The root of www.mydomain.com is currently served via an S3 static site.
I have configured rewrite rules in netlify.toml for each site (changing as appropriate to netlify2) as below:
[[redirects]]
from = "/netlify1/*"
to = "https://netlify1-abcd123.netlify.app/:splat"
status = 200
force = true
...and then added an Origin to Cloudfront which has the Origin Domain Name of https://netlify1-abcd123.netlify.app/ - all other Origin settings are the defaults.
I've then configured a Behaviour with a Path Pattern netlify1 that points to the netlify1 origin. Note that I cannot use the Default behaviour as the main index of www.mydomain.com is served via a static site hosted on S3.
This all works perfectly fine when serving the root / of my netlify app. I can navigate to www.mydomain.com/netlify1 and see the home page of my netlify app. However, anything that is not on the / of netlify doesn't get served.
I can see from the developer tools that a request is being made to www.mydomain.com/images/logo.png and www.mydomain.com/stylesheets/styles.css when trying to load the images and the styles. This returns a 404 because (I presume) they are not getting picked up by any Cloudfront Behaviour or Netlify rewrite rules.
So my question is. How can I make images, stylesheets and any page not on the root of the netlify apps work correctly? I can make it work by manually added every single potential path as a Behaviour on Cloudfront (i.e. configure a Behaviour with a Path Pattern of /images/* to point to the netlify1 Origin) - but that doesn't seem scalable or even correct.
I don't know whether I need to somehow rewrite all my URLs on the netlify app during building so that they become /netlify1/images and /netlify/page1 rather than /images and /page1 (the netlify apps are docs built with Sphinx docs), or whether this is something that needs to be handled via a Rewrite Rule in Lambda#Edge. I'm completely stumped.

What is the correct way to do a redirection from www. to the naked domain (Server or App or Domain Provider)?

I currently have an app that works with both www.domain.com and domain.com. Considering that this seems to be bad for SEO, I want it to always redirect to the naked domain.
My app works in this way:
Server: Google Cloud Platform (App engine)
App: Django
Domain provider: Godaddy
As I have researched the redirection can be done from any of these 3 options. So I want to ask: What is the best option and why?
I tested to do the redirection with GoDaddy on App Engine (An A record for www pointing to #) but when I set my custom domain in App Engine, I noticed that for the www.domain a C Record pointed to ghs.googlehosted.com setting was required in the app engine panel, I omitted that in order to do the redirection in GoDaddy, but the app wouldn't load when visiting from www.domain, a 404 error appeared (Also tried by omitting the addition of the www.domain altogether in app engine settings) So I wasn't able to accomplish this in the same fashion than an app that is hosted in a single server.
I think the easiest way would be to handle this inside the app itself like this site mentions

DNS hosting public and web application on different hosts

Here is my setup.
Public site hosted by squarespace.com (www.example-domain.com)
Web application (AWS EC2/ELB), i would like to be available via the same domain. (my.example-domain.com)
Custom profile pages available as www.example-domain.com/username
My question is how can i setup the DNS to achieve this? If can't do it just through DNS, any suggestions? The problem i am facing is that if squarespace.com is handling the www.example-domain.com traffic how can i have it only partially handle it for certain urls. Maybe i am going about this in the wrong was all together though.
The two first are ok. As you mention, (1) is not compatible with (3) for a pure DNS config as www of example-domain.com has to be configured to a single end-point.
Some ideas of non-DNS workaround:
Having the squarespace.com domain on sqsp.example-domain.com and configure your www domain to a custom web server on which you configure the root (/) to redirect (HTTP 300) to sqsp.example-domain.com. It will be quite transparent for the user, except in his browser address.
The same but setting on / a full page HTML iframe containing sqsp.example-domain.com.
The iframe approach is a "less clean", Google the solutions to build your opinion.
EDIT:
As #mike-ryan mentioned, there is the proxy solution as well where you configure you web server to request another server to get the content to return to your user. If you are already using AWS, a smart way to do this is to use CloudFront: you can setup CloudFront to proxy one server on one URL and proxy another server on other URL. Actually, this is maybe the faster to way to implement you need. Of course, a proxy is one more "hop", so it may add more delay.
If you really want to have content served from different servers while only using a single domain name, you'll need to set up a proxy server to handle the request routing for you. I am assuming your custom profile pages must be served from your EC2 instance.
Nginx will receive all requests, and will then decide whether they should be sent to Square Space or your web app. Requests will be reverse proxied to Square Space or to your app, depending on the URL.
This is similar to #smad's answer, except it will all be invisible to the users which IMHO is better than redirecting the user to a new domain name.
Example steps:
Set up an Nginx server, create two virtual hosts - one for my.example.com, and one for www.example.com
Create two upstreams in your Nginx config - one for Square Space, and one for your app
Configure the www.example.com virtual host to reverse proxy connections to the Square Space upstream, if the URL is "/". Otherwise, traffic should be proxied to your app upstream [0]
Configure the my.example.com virtual host to proxy all traffic to your app upstream
[0] how to reverse proxy via nginx a specific url?

Wordpress plugin for independent self-hosted CDN

I'm trying to set a cookieless subdomain to serve static content of my wordpress website. So I've tried self-hosted CDN solutions using WP SuperCache or W3 Total Cache plugin.
My wordpress is on the domain aljazair24.com and my CDN domain is static1.aljazair24.com. The domain and subdomain point to the same apache directory (/home/username/public_html).
Although WP SuperCache and W3TC plugins allow to set cookie domain to aljazair24.com, the subdomain static1.aljazair24.com still sends cookies to browsers...
I've tried to set cookie domain to www.aljazair24.com in order to avoid this but it doesn't work, since all www urls are redirected to non-www ones...
I was desperately looking for any WP plugin allowing to make "real" mirror resources, all this in order to avoid any interference at htaccess level. Unfortunately I didn't find anything ...
What should I do to make subdomain static1.aljazair24.com cookie-free ?
Page speed tests using YSlow
Grade F on Use cookie-free domains
There are 82 components that are not cookie-free
http://static1.aljazair24.com/wp-content/plugins/ajax-load-more/core/js/ajax-load-more.min.js
http://static1.aljazair24.com/wp-content/themes/aljazair/inc/js/flexslider.min.js
http://static1.aljazair24.com/wp-content/plugins/wysija-newsletters/js/validate/languages/jquery.validationEngine-ar.js
http://static1.aljazair24.com/wp-content/plugins/wysija-newsletters/js/front-subscribers.js
...
Have you tried Cloudflare? Most hosting providers have a built in extension and you dont have go through plugins like WP SuperCache or W3 Total Cache.