IDC フロンティア バーチャルホスト設定メモ

apacheは起動しているものとして、
IDCフロンティアで起動しているUbuntu16.04LTS にて特定のポートでWebページを公開する手順をメモ。

今回、公開するポートは8081番として手順を進める。

バーチャルホスト設定を追加

/etc/apache2/sites-available/ ディレクトリ配下に.confファイルを作成する。 

もともと、000-default.conf というファイルがおいてあるので、これをコピペで使えばOK
/etc/apache2/sites-available/000-default.conf

# コピーして作成(ファイル名はなんでもいい)
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/my-site-8081.conf

元のファイル(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

最低限こんな感じに書き換える。

sudo vi /etc/apache2/sites-available/my-site-8081.conf
<VirtualHost *:8081>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/my-site

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

VirtualHost のポートと、
DocumentRootを好きな場所にしただけ。

追加した設定ファイルを有効化する。

sudo a2ensite my-site-8081.conf

(実際にはenable-sitesディレクトリにシンボリックリンクが貼られるだけ)

ポート設定ファイルを編集

sudo vi /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
Listen 8081

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

追加したいポートのリッスンを追記するだけ
Listen 8081

index.htmlを配置するディレクトリを用意

DocumentRootに指定したディレクトリを作成しておく。

sudo mkdir -p /var/www/my-site

あとは、上記のディレクトリにhtmlファイルなどを配置しよう。

apacheユーザーがアクセス出来るような権限が必要という事に注意。

まぁ、上記のようにディレクトリ作れば問題ない。

apacheの再起動

# 再起動
sudo apache2ctrl restart

# 成功していればなにかしらレスポンスが返ってくるはず
curl localhost:8081

ファイアウォールとポートフォワーディング

上記の設定だけでは、まだ外部に公開された状態にはならない。
ポートをあけてやる必要があるのだが、
IDCフロンティアの場合、管理画面から簡単に設定できるぞ。

前回の記事: IDCフロンティア で仮想サーバー立ち上げる。

IPアドレス > ファイアウォール

コメント ソースCIDR タイプ ポートレンジ ステータス
http:8081 0.0.0.0/0 TCP 8081 Active

IPアドレス > ポートフォワード

コメント パブリックポート プライベートポート ステータス
http:8081 TCP:8081 8081 Active

となるよう設定すれば完成。

コメントを残す