我一直在寻找很长时间,我无法弄清楚。.我正在尝试创建一个名为bikestore的子域,这是example.com的一部分,(bikestore.example.com( - 我已经将此代码添加到etc/apache2/apache2.conf:
<VirtualHost *:80>
ServerName bikestore.example.com
DocumentRoot /var/www/bikestore.example.com
</VirtualHost>
我还在/etc/hosts中添加了此行:
(服务器IP(bikestore.example.com
并创建一个新目录(/var/www/bikestore.example.com(
我已经重新启动了apache,但是我无法访问bikestore.example.com,我也将cloudflare用于我的域。你知道我是否做错了什么?我正在使用Ubuntu 16.04和Apache
您必须在subdirectory sites-abailable中创建file bikestore.com.conf 喜欢/etc/apache2/sites-available/bikestore.example.com.conf
该文件不仅包含您发布的代码。
<VirtualHost *:80>
ServerName bikestore.example.com
DocumentRoot /var/www/bikestore.example.com
<Directory /var/www/bikestore.example.com>
# directory settings sample
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
# Protect files and directories from prying eyes.
<FilesMatch "(.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(.php)?|xtmpl)|code-style.pl|Entries.*| #Repository|Root|Tag|Template)$">
Order allow,deny
</FilesMatch>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel crit
ErrorLog ${APACHE_LOG_DIR}/bikestore.example.com.error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
CustomLog ${APACHE_LOG_DIR}/bikestore.example.com.access.log combined
</VirtualHost>
您还应在此配置中考虑一些安全性。
完成后,您可以使用:
启用网站并重新加载Apache设置sudo a2ensite bikestore.example.com
sudo服务apache2 reload
这将在目录网站启用
中创建指向您的配置文件的链接之后,您重新加载apache,如果一切顺利,网站将有效。
确实检查此教程:https://www.ostechnix.com/configure-apache-virtual-hosts-ubuntu-part-1/
https://httpd.apache.org/docs/2.4/vhosts/examples.html
https://www.digitalocean.com/community/tutorials/how-to-set-up-parce-apache-virtual-hosts-on-ubuntu-16-04