/etc/apache2にsites-available/000-default.confがありません

/etc/apache2にsites-available/000-default.confがありません

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、管理者が自由に作成、名前変更、削除、適切なコンテンツの入力などを行うことができます。000-default.com がない場合は、作成してください。

その後、電話してください

sudo a2ensite 000-default.conf

注意:

  • 仮想ホストは共存しています。私が理解したところによると、すでに非標準の設定がいくつかあるようです。仮想ホストが互いに競合しないように注意してください。おそらく、設定を含む apache2 の新規インストールが必要になるでしょう。

  • /etc/apache2/apache2.conf最終的にどのファイルが設定として読み込まれる (インクルードされる) かは、そのコマンド (指定されたファイルをインクルードする)などの他の設定ファイルによって異なります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

リロードでは、接続関連のデータがメモリ内に保持されますが、通常の新規インストールでは、どちらもほんの一瞬しかかかりません。

編集: 4 つの便利なコマンド (a2ensite、a2dissite、service apache2 restart/reload) についてのメモを追加しました。その後の編集で、質問により適合するように回答を再編成しました。

関連情報