所以我安装了Ubuntu 16和LAMP以及其他一些东西(比如FTP服务器......)。
我的VPS的IP是1.2.3.4。
我有2个域名,example.com和mydomain.com - 这两个域的A记录都指向1.2.3.4
如果我在浏览器中访问1.2.3.4和example.com以及mydomain.com,那么这三个都显示SAME数据,特别是/var/www/html
的内容 - 如果我更改此目录的内容,则会影响示例.com和mydomain.com以及1.2.3.4。
现在,如何为要读取的域设置其他文件夹?我想在example.com和mydomain.com上使用不同的数据 - 我想让它们从服务器上的不同文件夹中读取。我该如何设置呢?
答案 0 :(得分:1)
您要实现的目标在技术上定义为设置可以使用以下步骤设置的虚拟主机:
在您的Apache配置目录下,通常在 / etc / apache2 / ,您将找到名为 sites-enabled 的目录。
对于您的每个域,您需要配置一个特殊的配置文件,以便将它们指向正确的方向。该文件的名称通常是your-domain.conf。
这是文件的一个示例:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port
# that the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName your_domain
ServerAlias www.your_domain
ServerAdmin webmaster@your_domain
DocumentRoot website_directory
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory website_directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
保存文件后,您需要重新启动Apache服务器
/etc/init.d/apache2 restart
对每个域重复上述步骤 如果一切正常,您的网站将在您访问域名时显示。