This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
The community reviewed whether to reopen this question 2 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
作为一个完全的初学者,我一直在尝试在一个 Apache VPS 上托管多个域。教程包含太多信息,让我感到困惑。
下面我为初学者介绍如何使用 Ubuntu 和 Apache 在一台 VPS 服务器上托管多个域。
重要!您需要使用 root 帐户来执行大多数操作。
重要!如果您之前尝试对 apache 配置进行一些更改,请撤消它们。
创建虚拟主机
在服务器上为您的域创建文件夹。
例如:
将index.html 文件与任意文本放在每个文件夹中。
转到 /etc/apache2/sites-available 文件夹。
创建文件domain1
创建文件domain2
您可以用同样的方式创建子域。
启用已创建的站点
重新启动 apache
将域重定向到服务器
仅当您将域名重定向到服务器 IP 时,创建的 VirtualHosts 才会起作用。域名只是可以转换为 IP 号码的名称。
本地计算机
要在本地计算机上测试您的配置,您需要编辑主机文件。
它应该看起来像这样。
Hosts 文件告诉您的计算机域需要重定向到本地计算机。
重要!例如,如果您在现有域的主机文件中创建条目,
您将无法访问该网站。
服务器
为了将域重定向到您的 Web 服务器,您需要为给定域创建或修改“A”型 DNS 记录到您服务器的 IP 地址。您可以通过域名注册商提供的面板控制来完成此操作。
如果您不知道服务器的 IP 地址,请登录该服务器并输入命令行:
As complete beginner, I have been trying to host multiple domains on one Apache VPS. Tutorials had too much information that lead me to confusion.
Below I describe, for complete begginers, how to host multiple domains on one VPS server with Ubuntu and Apache.
IMPORTANT! You need to use root account to execute most operations.
IMPORTANT! If you have been trying to make some changes to apache configuration before, undo them.
Creating VirtualHosts
Create folders for your domains on server.
For example:
Put index.html file in each folder with any text.
Go to /etc/apache2/sites-available folder.
Create file domain1
Create file domain2
You can create subdomains same way.
Enable created sites
Restart apache
Redirecting domain to server
Created VirtualHosts will work only if you redirect your domain name to server IP. Domains are just names that can be translated to IP numbers.
Local computer
To test your configuration on local machine, you need to edit hosts file.
It should look like this.
Hosts file tells your computer that domain needs to be redirected to local machine.
IMPORTANT! If you create entry in hosts file for existing domain, for example
you will lose access to this website.
Server
In order to redirect domain to you web server, you need to create or modify "A"-type DNS record for given domain to IP address of your server. You can do it by panel control provided by your domain registrar.
If you do not know IP address of your server, log in to that server and type in command line:
过程是:
将两个域都指向 VPS 的 IP。
配置您在 VPS 上安装的网络服务器以响应这两个域。
对于带有 Passenger 的 Nginx,只需向 nginx.conf 文件添加条目即可。像这样:
检查您的网络服务器文档以执行类似的操作。
The procedure is:
Point both domains to the ip of the VPS.
Configure the webserver you have installed on your VPS to answer to those two domains.
In the case of Nginx with Passenger, it is a matter of adding entries to you nginx.conf file. Like this:
Check your webserver documentation to do a similar thing.
这始终是可能的...您始终可以使用 VPS 上的一两个 IP 地址来配置名称服务器。配置完成后,您可以开始使用这些名称服务器指向多个域。
我的 VPS 上只有一个 IP 地址,但我在那里托管着 35 个以上的站点......
This is always possible ... You can always configure name servers using one or two ip addresses on your VPS. Once configured, you can start pointing multiple domains using those name servers.
On my VPS there is only one IP address, but I am hosting 35+ sites there ....