I have a few domains hosted on the same server. These domains contain very similar types of data(similar to stackoverflow.com, stackexchange.com, serverfault.com). They all have the same idea, except minor things are different like images, titles, etc.
How can I use the same base code(like a php/javascript include, or even database) on each of these domains without copy/paste and having many copies to update when i make a change?
any advice would be great!
edit:
for a novice like myself in this department, where would I look to set variables in the virtual host which would tell the code which template/database my code should use for my specific host?
What kind of server setup or access would i need to have for this to be configured properly?
I am using PHP and MySQL for my sites.
If a thorough answer cannot be supplied, direct me as to how I can contact my hosting provider in such a way that they can understand and help me configure what I desire!
Set a variable in the virtual host that tells the code which template, database, etc. the code should use for that specific virtual host.
Related
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.
I have two domains abc.com and xyz.com pointing to the same NodeJS server. Based on the domain I want to load the configuration that will persist for that domain i.e. for xyz.com I wanna connect to Database1 and for abc.com I wanna connect to Database2.
How do I go about doing this? Is it even possible or recommended to do so?
I started with loading the configuration on the first request by getting the hostname from req.hostname. Is there any better way to do this?
Multiple strategies -
1. Deploy the same code multiple times but on different ports.
Your reverse proxy sends the request to the correct server. I do this currently by hosting multiple ghost blogs on the same vps. One runs on port 3000, another on 3010.
Pros - Less fragile setup, easier scaling, application need not be aware of operational environment. If one domain comes under attack, the other is not automatically a casualty.
Cons - Might not be possible in resource constrained environments. Deployments can involve repetitive work.
2. Read the hostname
Great option if the feature set is pretty much the same but only the domain name changes. You read the configuration file as you stated depending on the hostname.
Pros - Easier deployment, great option for resource constrained environments.
Cons - Unnecessarily tight coupling, all domains will become unavailable in case of server errors, scaling could be an issue.
Personally, I prefer deploying on different ports unless and until the code requires depending on hostnames. If you are just building a product where some unique identifier needs to be present in the URL like mycompany.slack.com then using subdomains in dns might be a better idea.
Searched the web and unable to find a solution. I have an umbraco site using IIS to host on a Windows server. Any ideas on approach to block users accessing site outside the UK? Htaccess approach would be too slow.... thank you in advance!
That's quite hard to do accurately, as you could have someone based in the UK using a European network provider, which means that they might appear to come from say Holland instead of the UK. It's also possible for people to spoof their location fairly easily if they really want to get at your site.
As Lex Li mentions there are plenty of commercial databases and tools for looking up a user's location, but the accuracy of these varies considerably, not to mention the fact that some of them only support IPv4. Any of these options are going to be slow though, as you'll have to check on every request. You also have to make sure you keep the databases up to date.
Another option would be to proxy your site through something like CloudFront or CloudFlare which both support blocking traffic by country.
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 want to create a website for myself that no one else will use at the moment.
Do I need to get a domain name to be able to access the website remotely or can I just use the host IP address when I want to go on it?
It depends on what you're looking to do. For example, Ruby on Rails and Sinatra languages can be locally hosted. So you can basically create the website without ever having to 'push' it to a domain. You'll definitely need a domain if you want to access it remotely - the domain name is basically a mask for an IP address anyway, so they're really somewhat the same.
You can also have basic JavaScript (JS) /HTML/CSS sites locally hosted as well. So you don't really need a domain, until you want people to actually start showing up to it remotely.
Hope this helps!