![/etc/apache2 中沒有sites-available/000-default.conf](https://rvso.com/image/1157736/%2Fetc%2Fapache2%20%E4%B8%AD%E6%B2%92%E6%9C%89sites-available%2F000-default.conf.png)
我正在嘗試為 Apache2 設定虛擬主機。有大量的教程,但它們都假設該文件/etc/apache2/sites-available/000-default.conf
在那裡。但如果我跑:
$ cd /etc/apache2/
$ ls
conf-available
$ cd conf-available
$ ls
javascript-common.conf
我找不到遇到相同問題的人。在開始此類教程之前我需要做任何事情嗎?
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
一切都是最新的。 Ubuntu 是 16.04 LTS。
答案1
其中的檔案/etc/apache2/conf-available
是管理員可以自由建立、重新命名、刪除、填寫適當內容等的檔案。
然後你應該打電話
sudo a2ensite 000-default.conf
注意事項:
虛擬主機共存 - 據我了解,您已經有一些非標準配置。當心虛擬主機相互衝突。您可能需要全新安裝 apache2 及其設定。
最終加載(包含)哪些文件作為配置取決於其他一些配置文件,例如
/etc/apache2/apache2.conf
其include
命令(然後包含指定的文件)。 Include 也可以在包含檔中呼叫。
僅供參考,apache2(版本 2.4.7)的 000-default.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 www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
您最好使用以下命令來啟用/停用站點,而不是透過建立符號連結來建立站點(您仍然可以這樣做,但是...它通常依賴幫助程式腳本,例如為了避免拼寫錯誤)
a2ensite 000-default
a2dissite 000-default
如果某些配置不起作用,您可以嘗試:
sudo service apache2 reload
甚至更深層的配置重新載入發生在:
sudo service apache2 restart
重新載入確實會在記憶體中保留一些與連接相關的數據,並且在典型的全新安裝中都只需要幾分之一秒的時間。
編輯:我添加了關於四個有用命令的註釋:a2ensite、a2dissite、service apache2 restart/reload,在隨後的編輯中,我重新組織了答案以更好地適應問題。