Let’s learn to configure Apache and Nginx to host a number of web sites.
Internet hosting websites on the Cloud server offers quite a lot of flexibility in comparison with shared internet hosting. You may set up something you want, scale it up or down, and configure it for higher efficiency and value optimization.
In the event you handle a number of enterprise websites however do not need to host them individually, you possibly can reap the benefits of this Digital Server
on internet servers. Let’s check out this situation.
I’ve the next two websites that I want to level to my one cloud VM.
- lab.geekflare.com
- gf.dev
Earlier than implementation, let’s perceive the way it works.
The idea of getting a number of web sites on a single internet server occasion is talked about Digital Server
. It’s outlined within the configuration file together with the URL. When a request is made to an outlined URL, the net server would ahead the visitors from the respective Doc Root
.
Configure Digital Host in Apache to host a number of domains
- Login to the Apache HTTP server
- Go to the apache-conf location. (in commonplace set up – you will discover it right here /and so forth/httpd/conf/httpd.conf)
- Again up the httpd.conf file
- make a
VirtualHost
container as beneath i’ve accomplished for 2 domains.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /decide/htdocs/lab
ServerName lab.geekflare.com
ErrorLog logs/lab.geekflare.com-error_log
CustomLog logs/lab.geekflare.com-access_log widespread
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /decide/htdocs/gf-dev
ServerName gf.dev
ErrorLog logs/gf.dev-error_log
CustomLog logs/gf.dev-access_log widespread
</VirtualHost>
Comment: Change the worth for ServerAdmin, DocumentRoot, Server title, ErrorLog, Customized log primarily based in your want.
- Restart Apache HTTP and check each URLs.
Configure Digital Host in Nginx to host a number of domains
- Login to the Nginx server
- Go to the situation the place you put in Nginx. (within the default location – you will discover it right here /and so forth/nginx/)
There are a number of methods to attain this. Or you possibly can change nginx.conf
file or customized file if in case you have one. You too can use one customized.conf
below the conf.d folder. Select what works for you and again it up when you change an present file.
- Create a server block for each URLs as I’ve proven beneath.
server {
pay attention 80;
root /decide/htdocs/lab;
index index.html index.htm;
server_name lab.geekflare.com;
location / {
try_files $uri $uri/ =404;
}
}
server {
pay attention 80;
root /decide/htdocs/gf-dev;
index index.html index.htm;
server_name gf.dev;
location / {
try_files $uri $uri/ =404;
}
}
Comment: Change the worth for carrot, server title primarily based in your want.
- Restart Nginx and check each URLs
Do not forget to replace your URL’s DNS document to map to server IP. As soon as accomplished, it is best to be capable of entry the URLs supplied via the above configuration you made.
Conclusion
That was the short information to internet hosting a number of domains in a single internet server occasion like Apache or Nginx. As soon as your web site is dwell, remember to check it for safety vulnerabilities.