Hello
In a previous web-project of mine I had a website where multiple businesses could register. They each had their own subdomain. E.g: business1.example.com, business2.example.com,...
They all had the same page but only the data was relative to the business.
My HTML/Askama:
<html>
...
<span id="business-name">{{ name }}</span>
...
</html>
My database table was like this:
+----+-----------+------------------+
| ID | subdomain | name |
+----+-----------+------------------+
| 1 | business1 | My Business 1 |
| 2 | business2 | Another business |
+----+-----------+------------------+
And when my site was visited, I retrieved the Host-Headers and checked for the subdomain. If the subdomain of the request matched with a row in my table, I'd display the data of that business. So business1.example.com would return the following HTML:
<html>
...
<span id="business-name">My Business 1</span>
...
</html>
This worked fine. I used a wildcard SSL-certificate to allow all subdomains.
Now I want to do the same, but with full domains. When a business registers I will buy a domain name. And in the DNS-records I will make an A-record pointing to the server where my Actix/Web project runs. This means that multiple domain names like for example business1.com and business2.com will all refer to 84.1.1.1 (my VPS IP).
When a request comes I can check from what domain-name it comes. My database-table will be as follow:
+----+---------------+------------------+
| ID | domain | name |
+----+---------------+------------------+
| 1 | business1.com | My Business 1 |
| 2 | business2.com | Another business |
+----+---------------+------------------+
I'll retrieve the host-headers from the request and check if the domain-name exists in my database. If it does, I'll show the name of that business.
This way, I could have one code-base and one HTML-file but allow businesses to have their own domain-name.
My question:
- Is this possible in Rust/Actix-web?
- Did I overlook something?
- How would this work for SSL-certificates? Can I just, when a business registers, add a SSL certificate for that domain name to Ngix?
- Is there a better way to do this?