UJP - Raspberry Pi3でApache2の設定,apache2.confとa2ensiteとa2dissite

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

  • カテゴリ Raspberry Pi の最新配信
  • RSS
  • RDF
  • ATOM

ブログ - Raspberry Pi3でApache2の設定,apache2.confとa2ensiteとa2dissite

Raspberry Pi3でApache2の設定,apache2.confとa2ensiteとa2dissite

カテゴリ : 
PC » Raspberry Pi
ブロガー : 
ujpblog 2017/10/18 21:44
 Raspberry PiのRaspbian OSはDebianの派生ですが,そのaptでインストールされるApache2は設定ファイルがhttpd.confじゃなくapache2.confである事以外にも,独自のルールがある模様.

apache2.conf

 メインとなるのがこのファイル.パスはこちら.
/etc/apache2/apache2.conf
 コメントと空白行を取り除いて設定ファイルをリストして見る.
root@commet:/etc/apache2# grep -v ^# apache2.conf|grep -v "^$"🆑
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load🈁
IncludeOptional mods-enabled/*.conf🈁
Include ports.conf
<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all denied
</Directory>
<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>
<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf🈁
IncludeOptional sites-enabled/*.conf🈁
ServerName commet
root@commet:/etc/apache2#
 最後のcommetというのは,このセットアップをやっている時につけたもの.注目するのは,IncludeOptionalとなっている部分.
 sites-enabledから確認.
root@commet:/etc/apache2# cd sites-enabled🆑
root@commet:/etc/apache2/sites-enabled# ls -la🆑
合計 12
drwxr-xr-x 2 root root 4096 10月 18 20:47 .
drwxr-xr-x 8 root root 4096 10月 18 21:42 ..
lrwxrwxrwx 1 root root   35  9月 13 01:15 000-default.conf -> ../sites-available/000-default.conf🈁
root@commet:/etc/apache2/sites-enabled#
 000-default.confというファイルがある.オリジナルはディレクトリsites-availableに入っているものからのリンク.

a2ensiteとa2dissiteをつかう

 DebianのApache2では,設定ファイルをsites-availableにいれて,sites-enabledにリンクを貼る事で設定を有効化させるルールという事でした.
 sites-availableディレクトリに移動して,ファイルを確認.
root@commet:/etc/apache2/sites-available# ls -la🆑
合計 20
drwxr-xr-x 2 root root 4096 10月 18 20:49 .
drwxr-xr-x 8 root root 4096 10月 18 21:42 ..
-rw-r--r-- 1 root root 1366 10月 18 20:47 000-default.conf
-rw-r--r-- 1 root root 6437  7月 19 03:25 default-ssl.conf
root@commet:/etc/apache2/sites-available#
 000-default.confの中身を確認.同じように不要なコメント行とブランク行を削除.
root@commet:/etc/apache2/sites-available# grep -v "#" 000-default.conf|grep -v "^$"🆑
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
root@commet:/etc/apache2/sites-enabled#
 VirtualHost設定が入っていることが確認.000-default.confを元に設定ファイルを作成する.
root@commet:/etc/apache2/sites-available# cp 000-default.conf 001-www.ujp.jp.conf🆑
root@commet:/etc/apache2/sites-available#
 設定ファイルを編集し,a2ensiteコマンドを実行する.先ずはコマンドパスを確認.
root@commet:/etc/apache2/sites-available# which a2ensite🆑
/usr/sbin/a2ensite🈁
root@commet:/etc/apache2/sites-available#
 存在していたので実行.
root@commet:/etc/apache2/sites-available# a2ensite 001-www.ujp.jp.conf🆑
Enabling site 001-www.ujp.jp.🈁
To activate the new configuration, you need to run:
  service apache2 reload🈁
root@commet:/etc/apache2/sites-available#
 有効化された模様.ファイルがsites-enabledにリンクが作成されているか確認.
root@commet:/etc/apache2/sites-available# ls -la /etc/apache2/sites-enabled/🆑
合計 12
drwxr-xr-x 2 root root 4096 10月 18 22:29 .
drwxr-xr-x 8 root root 4096 10月 18 21:42 ..
lrwxrwxrwx 1 root root   35  9月 13 01:15 000-default.conf -> ../sites-available/000-default.conf
lrwxrwxrwx 1 root root   38 10月 18 22:29 001-www.ujp.jp.conf -> ../sites-available/001-www.ujp.jp.conf
root@commet:/etc/apache2/sites-available#
 リンクが有効になっていることを確認.次に設定に記述ミスがないか確認して見る.
root@commet:/etc/apache2/sites-available# which apachectl🆑
/usr/sbin/apachectl
root@commet:/etc/apache2/sites-available#
 configtestを実行.
root@commet:/etc/apache2/sites-available# apachectl configtest🆑
Syntax OK
root@commet:/etc/apache2/sites-available#
 a2dissiteを使って設定を削除してみる.まずはコマンド実行.
root@commet:/etc/apache2/sites-available# a2dissite 001-www.ujp.jp.conf🆑
Site 001-www.ujp.jp disabled.
To activate the new configuration, you need to run:
  service apache2 reload
root@commet:/etc/apache2/sites-available#
 リンクを確認.
root@commet:/etc/apache2/sites-available# ls -la /etc/apache2/sites-enabled/🆑
合計 12
drwxr-xr-x 2 root root 4096 10月 18 22:46 .
drwxr-xr-x 8 root root 4096 10月 18 21:42 ..
lrwxrwxrwx 1 root root   35  9月 13 01:15 000-default.conf -> ../sites-available/000-default.conf
root@commet:/etc/apache2/sites-available#
 設定ファイルが戻ることが確認できたので,再度設定して反映させる.
root@commet:/etc/apache2/sites-available# a2ensite 001-www.ujp.jp.conf🆑
Enabling site 001-www.ujp.jp.
To activate the new configuration, you need to run:
  service apache2 reload
root@commet:/etc/apache2/sites-available# apachectl stop🆑
root@commet:/etc/apache2/sites-available# apachectl start🆑
root@commet:/etc/apache2/sites-available#

トラックバック


広告スペース
Google