Generic website infrastructure setup
This pages aims to provide links toward other reliable sources, to understand the different topics it's important to understand the principle that internet use.
1. Internet is an IP network, meaning that to reach every server an IP is required
2. When a name is used to reach a server, this name need to be translated to an IP by a Domain name server (DNS)
3. Your network use a private range of IP address therefore can't be reached from internet without a specific configuration
Domain, Domain name server (DNS) and DynDNS
Wikipedia: A DNS is important when you want to reach your server from internet because you don't want to learn your IP by heart, you'd rather buy a domain like mycompany.org and use it to reach your server. When you type "www.mydomain.com" in a browser, your computer will call the default DNS; if this DNS doesn't know the IP attached to mycompany.org it will check with other DNS until it gets the answer, sometime www.mycompany.org can refers to another domain like datacenter1.mycompany.org. In this the case, the DNS will look for the IP attached to datacenter1.mycompany.org.
When you own a domain, you also own all the sub-domain like www.mycompany.org, erp.mycompany.org, yyy.xxx.mycompany.org ...; you can map this domain and its sub.domain to either an IP or another domain, usually with the company that sold you the domain. Here the main type that you will have to configure on the domain vendor portal:
- "CNAME" record: used to map to another domain
- "A" record: use to map an IP v4
- "AAAA" record: use to map an IP v6
- In case you don't own a fixed IP, you can use a Dynamic DNS service: there is a daemon running on your network that will keep updating your IP in the DNS (usually the internet modem/gateway have this function). Often you will have to configure a dynamic DNS username and password on your domain vendor portal.
Here the example for OVH: https://docs.ovh.com/gb/en/domains/web_hosting_how_to_edit_my_dns_zone/
Port Forwarding, DMZ and Reverse Proxy
Once your Domain/subdomain refers to your IP address, Internet requests will arrive to your internet gateway, but you'll need to setup port forwarding in order to forward those requests toward your web server.
The default internet port are 80 for http and 443 for https, once the portforwarding is configured for those port (80 & 443), it'll affect all the web traffics coming on this port. A simple port forwarding will work if you have a single web server (could host several websites) but if you have multiple web servers you may have to forward your traffic to a reverse proxy that will be able to redirect the traffic based on the domain/subdomain or/and url.
If you want to be sure that internet traffic can't reach the other device on your network (LAN), you can place the reverse proxy in a DMZ with firewall rules that allow only the traffic from internet to the reverse proxy and from the reverse proxy to specific IP on your local LAN (ie. your servers) but the firewall will block all other traffic coming from internet. For such setup there is an open source security appliance called pfSense that is able to do the firewall and the reverse proxy (with the module called HAProxy), pfSense can be installed on an old PC or deployed on a virtual machine.
Virtual host  is a method which aims to define with a configuration file of the web server (e.g Apache) a domain/Url called by the user's browser to access to your application; for example a virtual host configuration can be setup for:
- www.mycompnay.org, the configuration file will define where to look for the pages like /usr/share/mangento/myshop ;
- cloud.mycompany.org, the configuration file can define a reverse proxy to redirect the traffic to http://localhost:8888 in order to show the nextcloud pages;
- dolibarr.mycompany.og, the configuration file could be the one to access your Dolibarr .
The SSL encryption enable the encrypt the traffic between the user web browser and the server so even if someone is able to intercept the traffic he won't be able to see you passwords, website content ... the SSL encryption is configured at the virtual host level
- Certificat generation with Openssl (selfsigned)
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650
You can also add -nodes if you don't want to protect your private key with a passphrase, otherwise it will prompt you for "at least a 4 character" password. The days parameter (3650) you can replace with any number to affect expiration date. It will then prompt you for things like "Country Name" but you can just hit enter and accept defaults.
Add -subj '/CN=localhost' to suppress questions about the contents of the certificate (replace localhost with your desired domain)
Self-signed certs are not validated with any third party unless you import them to the browsers previously. If you need more security, you should use a certificate signed by a trusted CA like let's encrypt (free), globalsign, Norton ...
- Certificat generation with Let's encrypt
- Configuration of the virtual host
- Let's encrypt certificate renewal
- LXC container