Answer the question
In order to leave comments, you need to log in
Auto create a subdomain with the site?
Hello. I plan to open my own service of donation pages for Minecraft game servers. The idea looks like this:
The user registers on the service, indicating the name of his server, the script processes the form and executes the sh script on a dedicated server under Debian. The sh script creates a folder with the name of the user's server, unpacks the archive prepared in advance, creates a config.php file with standard settings for my cms, indicating the site address, names there, and creates a database. As a result, we get a subdomain with an installed and mood script.
What I have:
Xeon E5 dedicated machine.
Donate page
script Script for sh with creating a directory and unpacking the archive
Knowledge and some budget.
Unresolved points:
How to use a php form to execute a Sh script with parameters like %username_dir% , %site_title%, so that Sh would create a folder with a name, unpack the existing site archive there and create a config according to the template with the address, site name specified by the user during registration.
I could in principle hire a freelancer, but I want to personally understand the principle and develop. Thanks in advance for any ideas.
Answer the question
In order to leave comments, you need to log in
When I first got acquainted with a server that creates third-level subdomains, and also knows how to "park" second-level domains, I first of all imagined that directories for user scripts were automatically created there, a config for Apache, and some kind of root daemon does sudo service apache reload
But on it turned out not to be the case.
1. There is a rule in DNS (see https://toster.ru/q/7456) - all ***.myservice.ru subdomains are sent to one IP
Replace 192.168.1.1 with your server IP
2. Do not use Apache/nginx binding a virtual host to a domain name (myservice.ru or another), all requests are sent for processing to one script (PHP?)
nginx
{
listen 80;
# server_name не указывать
}
$domainName = $_SERVER['HTTP_HOST']; // vasya.myservice.ru
$userDomain = $db->findUserByDomain($domainName);
echo 'Владелец этой страницы: ', $userDomain->fullName; // Владелец этой страницы: Вася
// ...
WildCard to the rescue,
+checking the subdomain name, no folders with sites are needed
When a user adds all this, let php create newusers.txt, and by cron you will run some kind of script that parses this file in turn and creates everything you need. depending on how often users registrate and set the time for crowns. if it's very frequent let the script be checked every few minutes. and at the end of the script, let it delete the . at the expense of subdomains have already been said) although there are many options when a folder is simply created and it becomes a subdomain. htaccess to help)
system()
upd: In general, such things are resolved through htaccess.
It couldn't be easier:
1. In DNS, we prescribe * and IP-shnik.
2. Checking the HOST on the URI router when requesting anyusername.servername.com
3. Making the transfer to the right folder (or loading the right script) depending on the 3rd-level domain from which we take the user (after checking its existence).
4. Also, you can do it with system services that are not user subdomains with a transparent "rolling" of the session.
Everything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question