apache - 子域不工作(Ubuntu 16.04 和 Apache)
问题描述
我一直在到处寻找很长一段时间,我就是想不通。我正在尝试创建一个名为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
解决方案
您必须在子目录sites-available中创建文件bikestore.example.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 重新加载
这将在启用站点的目录中创建指向您的配置文件的链接
之后你重新加载 apache,如果一切顺利,网站就会工作。但如果没有,你会在你的错误文件夹 /var/log/apache2 中找到错误
请检查本教程: 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-apache-virtual-hosts-on-ubuntu-16-04
推荐阅读
- javascript - 是否可以使用 firebase 添加 google 和 Facebook 身份验证?
- c++ - C++ 字符数组加法
- html - Curl - 从文本文件中加载多个地址
- apache - 如何在 apache 中使用基于表单的 LDAP 身份验证
- javascript - LINQ.JS 中的“任何列表”选择器
- spring-boot - 使用 IntelliJ IDEA 遇到 JPA 多对多关系构建时间错误
- node.js - npm uninstall * 命令是否会在卸载 package.json 的依赖项时也删除全局安装?
- windows - Windows中python文件的FileNotFoundException
- ruby-on-rails - Ruby on Rails 洗劫 gem 搜索
- java - 这些解决方案中的哪一个具有更好的风格/性能?