4_How to Host Multiple Websites on One Server
地址:https://www.codewithharry.com/blogpost/host-multiple-websites-ubuntu-vps/
How to Host Multiple Websites on Ubuntu VPS?
An apache2 web server provides robustness and scalability for hosting multiple websites on your Ubuntu VPS. This means you can utilize the power of your VPS hardware without any downtime on your website.
We can configure apache2 to host multiple websites on the same VPS. To achieve this using apache, we create virtual hosts corresponding to each domain or individual site. A virtual host is a way to direct traffic corresponding to an IP to a specific directory on our VPS. This way we will be able to host multiple websites on a single Ubuntu server.
How to setup a virtual host in apache2
If you haven't already installed apache2, you can do so by entering the below command in the ubuntu terminal
Assuming you have apache2 installed on your machine, all you need to do now is to follow the steps outlined in the next section to host multiple websites. For the sake of this tutorial, I will assume that we have to host 2 websites codewithharry.com and programmingwithharry.com on our ubuntu VPS. We will point the domains to the IP address of our droplets. Here is how A record is set up in GoDaddy.
The process is pretty similar for other domain providers
Let's set up our virtual hosts now
Step 1 - Creating Directories for individual sites
Let's create individual directories to store the contents of codewithharry.com and programmingwithharry.com. Execute the commands below to create these directories inside the /var/www folder
Step 2 - Transfer the site contents
Transfer the index.html and related files to the individual site directories using Filezilla
Step 3 - Creating the VirtualHost files
Create a new file inside the /etc/apache2/sites-available/ directory by firing the following commands below:
Once the codewithharry.com.conf file is created. paste the below contents inside it
Repeat the same for programmingwithharry.com by executing the command below:
and paste the below contents:
Step 4 - Enable the VirtualHosts
In order for these virtual host files to function correctly, we need to enable them.
Enter the directory where we have created virtual hosts:
Execute the following commands to enable the virtual hosts:
Finally, you will have to restart the apache server:
Step 5 - Test the configuration
Test the configuration of these virtual hosts by visiting your domains. You can configure as many virtual hosts as you want for your domains and this technique can help you power many websites on a single VPS.
Hope this will help you host your websites and save some money on VPS. Happy Coding!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现