Apacheの設定

インストール後設定では、ドキュメントルート(トップページは)は、/var/www/html になっています。

フォルダの基本設定

基本設定は、000-default.conf をコピーし編集します。

$ cd /etc/apache2/sites-available
$ sudo cp 000-default.conf myhttp.conf
$ sudo vi myhttp.conf

以前のバージョンと同じにするため、DocumentRoot を書き換えます。

<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

        # 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

defaultを無効にし、myhttpを有効にし、元からあった html フォルダを削除し、apache2を再起動。

$ sudo a2dissite 000-default.conf
$ sudo a2ensite myhttp
$ sudo rm -rf /var/www/html
$ sudo service apache2 restart

SSLの基本設定

まずは、公開用のフォルダ作成。

$ sudo mkdir /var/www-ssl
つぎに、なんちゃって証明書を作成します。
$ sudo mkdir /etc/apache2/ssl
$ sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

設定ファイルはdefault-sslをコピーし編集します。

$ cd /etc/apache2/sites-available
$ sudo cp default-ssl.conf myhttps.conf
$ sudo vi myhttps.conf

修正が必要なのは、SSLCertificateKeyFile まで。SSLCertificateKeyFile 以降はそのまま。

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                # 管理者のメールアドレス
                ServerAdmin webmaster@localhost
                # 公開するフォルダ
                DocumentRoot /var/www-ssl

                # 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}/ssl_error.log
                CustomLog ${APACHE_LOG_DIR}/ssl_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

                #   SSL Engine Switch:
                #   Enable/Disable SSL for this virtual host.
                SSLEngine on

                #   A self-signed (snakeoil) certificate can be created by installing
                #   the ssl-cert package. See
                #   /usr/share/doc/apache2/README.Debian.gz for more info.
                #   If both key and certificate are stored in the same file, only the
                #   SSLCertificateFile directive is needed.
                SSLCertificateFile      /etc/apache2/ssl/apache.pem
                SSLCertificateKeyFile   /etc/apache2/ssl/apache.pem

default-sslを無効にし、myhttp-sslを有効にし、apache2を再起動。

$ sudo a2dissite default-ssl.conf
$ sudo a2ensite myhttps.conf
$ sudo a2enmod ssl
$ sudo service apache2 restart

ubuntu/v1404/apache_の設定.txt · 最終更新: 2018/03/18 09:56 (外部編集)
 
特に明示されていない限り、本Wikiの内容は次のライセンスに従います: CC Attribution-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki