Best practice for setting up a web root folder under a path directed by a load balancer? - .htaccess

A (for me) somewhat unusual setup scenario:
Access to a single subdomain, let's call it test.domain.com
The need to host sites on separate instances directed by paths, for example: test.domain.com/site1 goes to VM1, test.domain.com/site2 goes to VM2, etc.
At the moment I have a load balancer that directs traffic depending on URL-path, which works fine (using Google Cloud).
The part I'm unsure about is how to manage is the fact that some solutions can't take the path into account when linking dependencies or redirecting.
For example a Wordpress installation ignores the rewritten path of test.domain.com/site1/index.php and considers test.domain.com to be the correct root/base URL, as the installer goes from
test.domain.com/site1
to
test.domain.com/wp-admin/setup-config.php (results in a 404)
The optimal solution in my scenario would require as little individual customization on the actual server itself, as the things that'll run on the individual VMs necessarily isn't based on the same framework etc.
Is there a general practice to work with path-distributed traffic in this way – should I just resort to actually adding a subfolder in the root of each VM and not bother rewriting the path in Google Cloud? Or it is it possible to manage this using .htaccess somehow? I might be making this a lot more complicated than it has to be...
I hope my explanation is clear enough, otherwise I'm happy to elaborate if needed.

Related

Drupal: URL redirects in .htaccess for multiple sites and a single codebase

I'm using Drupal 8. Multiple sites sharing a single codebase. One .htaccess file for all.
I am receiving the same "page not found error" across all sites. Hackers attempting to break in to the site, presumably.
For example, someone tries to visit https:domain1/wp-admin/admin-ajax.php and https:domain2/wp-admin/admin-ajax.php ... Different domain names, but always the same addresses.
Other addresses include /phpmyadmin/scripts/setup.php and /1/wp-includes/wlwmanifest.xml and so on.
Using .htaccess, what is the most efficient means of redirecting all of these to an internal or external site so that my pages are not even served?
Thank you!
So, the way Drupal and the web server work is that when request arrives, if it matches “serverName” and document root and they points to Drupal then the web-server will hand that to Drupal to handle.
So, you have to ask if this is Drupal destined and if so, handle the redirect at Drupal (probably using the redirect module )
If you want set it up at at web-server level and you have access or using .htaccess then like :
RedirectMatch ^/wp-admin/(.*)$ http://example.com/404/$1
Note, there are plenty of other ways to write the above , but it’s simplest and lightest
I think this is a very common issue about CMS vulnerabilities and hosting security. And security issues is something that can not be done by a simple static action because there's always a new vulnerability. So be careful to always run :
composer update
To have always the last bug fixes and securities updates. Specially when you use modules like webform. At the moment Drupal offers more than one module for better securing your app. And in your case you need to identify IP addresses used by hacking robots and blocking them by using Perimeter .
The good news that the community arround Drupal is very concerned about security. For further reading and securing Drupal you can uses those modules but the more modules you install the more you have performance issues:
https://www.drupal.org/project/clamav
https://www.drupal.org/project/file_upload_secure_validator
https://www.drupal.org/project/key
https://www.drupal.org/project/csp
https://www.drupal.org/project/noopener_filter
https://www.drupal.org/project/hsts
https://www.drupal.org/project/securelogin
...
I also recommend the use of fast 404/403 Drupal error pages to not allow using of Database or more code running to serve that kind of pages.

Splitting domain name over two hosts

I want to make the move to Webflow for a client project that require a CMS. I would like some more information about the logistics and best practices of adding domains though.
Say for instance I have a client’s home page and a blog hosted on Webflow and this is accessed by their custom domain. what if I still need to host additonal files, and other pages on a traditional hosting platform with cPanel?
Would it be best to point the www.clientwebsite.com to Webfllow and keep the clientwebsite.com pointing at traditional host with a 301 redirect to the www.clientwebsite.com
I could still have pages on the traditional host for example clientwebsite.com/page.html while being able to add additional pages to Webflow e.g. www.clientwebsite.com/page.html
Basically I want to be able to use the same domain name on both Webflow and traditional hosting with cPanel, I just want to know what the best way to do this is, is there a better way to achieve this, is there anything to be careful of/ or would be considered bad practice?
Thanks in advance
Typically, one hostname will resolve to one IP address, so one hosting platform has to be the entry point. If the sites can be logically separated, you should probably just use different hostname (blog.example.com, www.example.com, something.example.com) and point them to different hosting platforms.
If you need to have content from the 2 platforms served under the same hostname, then one platform will be the entry point and there it will have some internal rewrite/proxy rules to fetch and serve content from somewhere else. This is easily doable in all modern webservers (nginx, apache..) but I am not sure your CMS platform will allow it.

Folder Structure for Nodejs Multi Subdomain site

So i am building a website using NodeJS where i will use Nginx as a reverse proxy to my app/apps. I will be using jade and sharing some layouts between subdomain and displaying specific content according to subdomain. I am trying to figure out from alot of research the best method of structuring the app. Is the best way to run each subdomain as a separate app on the same server? Or can i link them as one app? Please share your ideas and suggestions so i can make a decision and begin my coding :)
The main issue with using the same domain across multiple apps is security in regards to cookies. If apps are independent, then you might want to ensure a vulnerability in one app would not necessarily affect your other apps.
Otherwise, with nginx, there is really no limitation on your setup, however you decide to go. You can use nginx to easily join or disjoin multiple domains and/or ports/servers, into whatever setup you wish.
Whether you decide to go with multiple domains or multiple paths on a single domain have more to do with what kinds of apps you have in mind, and how logically separate would they appear to be from one another. With the help of the rewrite directive, even if you make a "wrong" choice initially, if you do have a desire, you could always fix it later on (preserving all existing links flawlessly), pretty much without any ill effect.
I am running multiple web applications (totally separated in different folders and running on different ports) on server with nxinx as proxy for different subdomains. However, if you want to make more subdomains for one application, the best way should be to structure it by URL.
For example you have mysite.com/books but you want books.mysite.com to be go to domain for books. You make proxy in nginx configs to redirect traffic from mysite.com/books to books.mysite.com.

I need to speed up my site and reduce the number of files calls

My webhost is aking me to speed up my site and reduce the number of files calls.
Ok let me explain a little, my website is use in 95% as a bridge between my database (in the same hosting) and my Android applications (I have around 30 that need information from my db), the information only goes one way (as now) the app calls a json string like this the one in the site:
http://www.guiasitio.com/mantenimiento/applinks/prlinks.php
and this webpage to show in a web view as welcome message:
http://www.guiasitio.com/movilapp/test.php
this page has some images and jquery so I think this are the ones having a lot of memory usage, they have told me to use some code to create a cache of those files in the person browser to save memory (that is a little Chinese to me since I don't understand it) can some one give me an idea and send me to a tutorial on how to get this done?. Can the webview in a Android app keep caches of this files?
All your help his highly appreciated. Thanks
Using a CDN or content delivery network would be an easy solution if it worked well for you. Essentially you are off-loading the work or storing and serving static files (mainly images and CSS files) to another server. In addition to reducing the load on your your current server, it will speed up your site because files will be served from a location closest to each site visitor.
There are many good CDN choices. Amazon CloudFront is one popular option, though in my optinion the prize for the easiest service to setup is CloudFlare ... they offer a free plan, simply fill in the details, change the DNS settings on your domain to point to CloudFlare and you will be up and running.
With some fine-tuning, you can expect to reduce the requests on your server by up to 80%
I use both Amazon and CloudFlare, with good results. I have found that the main thing to be cautious of is to carefully check all the scripts on your site and make sure they are working as expected. CloudFlare has a simple setting where you can specify the cache settings as well, so there's another detail on your list covered.
Good luck!

Prefixed / Suffixed Environmental Domain Names

Overview
I'm currently implementing a multiple environment plug-in for the CodeIgniter framework as a learning experience; however, I have run into an issue which could be solved multiple ways. I am unsure of which approach [is best] to take, hence this question. I've done a quick search of Stack Overflow and the Web on this subject and have found little definitive results.
Problem
When developing a website you generally have a setup which mimics a similar structure to this: Local - Testing - Live. In having this structure you'll almost certainly have a domain structure to be able to view the website in their different environments, whether this be a prefixed structure, or suffixed.
Question
What method of defining a URL for each of the above environments is best practise, is it the prefixed approach:
local.site.com
test.site.com
site.com
or the suffixed approach:
site.local
site.test
site.com
Even if the outcome of this question is that I should provide support for both prefixed and suffixed, it would still be beneficial to know which is the best practise to use.
I think it's a matter of taste, my thoughts on it - .local is non-existing TLD, and it is a common practice to use .local for local resources. If your dev/test sites don't need to be globally accessible, it seems OK to use it, but if you ever want to show this site to someone from outside, he will not be able to reach it. Unlike .local, .test is a non-existent TLD which nobody uses so far, but one day it may be assigned and your .test sites will conflict with other sites, I'd never use it.
While site.com is your domain, you are free to define any subdomains inside it, and decide which subdomains you want to publish on a globally-accessible DNS server etc..
Personally, I prefer prefixes.

Resources