3.4. 設定の実例
SELinux でどのように Apache HTTP Server を補完するのか、 Apache HTTP Server の全機能をどのように管理するのかなど、 実践的な例を以下に示します。
3.4.1. 静的なサイトを実行する リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
静的な web サイトを作成する場合は、 その web サイトの
.html ファイルに httpd_sys_content_t タイプのラベルを付けます。 デフォルトでは、httpd_sys_content_t タイプのラベルが付いたファイルには Apache HTTP Server による書き込みは行なえません。 次のように、読み取り専用 web サイト向けのファイルを格納する新しいディレクトリを作成します。
- root ユーザーで
mkdir /mywebsiteを実行し最上位にディレクトリを作成します。 - root ユーザーで
/mywebsite/index.htmlファイルを作成します。 以下のコンテンツを/mywebsite/index.htmlにコピーして貼り付けます。<html> <h2>index.html from /mywebsite/</h2> </html>
<html> <h2>index.html from /mywebsite/</h2> </html>Copy to Clipboard Copied! Toggle word wrap Toggle overflow /mywebsite/および配下のファイルやサブディレクトリへの Apache HTTP Server 読み取り専用アクセスを許可するため、/mywebsite/にhttpd_sys_content_tタイプのラベルを付けます。root ユーザーで次のコマンドを実行してラベルの変更をファイルコンテキスト設定に追加します。semanage fcontext -a -t httpd_sys_content_t "/mywebsite(/.*)?"
# semanage fcontext -a -t httpd_sys_content_t "/mywebsite(/.*)?"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - root ユーザーで
restorecon -R -v /mywebsiteを実行してラベルの変更を行ないます。restorecon -R -v /mywebsite
# restorecon -R -v /mywebsite restorecon reset /mywebsite context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /mywebsite/index.html context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0Copy to Clipboard Copied! Toggle word wrap Toggle overflow - この例の場合、 root ユーザーで
/etc/httpd/conf/httpd.confを編集します。 既存のDocumentRootオプションをコメントアウトします。DocumentRoot "/mywebsite"オプションを追加します。 編集結果は以下のようになるはずです。#DocumentRoot "/var/www/html" DocumentRoot "/mywebsite"
#DocumentRoot "/var/www/html" DocumentRoot "/mywebsite"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - root ユーザーで
service httpd statusを実行し Apache HTTP Server の状態を確認します。 サーバーが停止している場合は、 root ユーザーでservice httpd startを実行してサーバーを起動します。 サーバーが実行中の場合は、 root ユーザーでservice httpd restartを実行しサーバーの再起動を行ないます (これによりhttpd.confへの変更がすべて適用されます)。 - web ブラウザで
http://localhost/index.htmlに行きます。 次のように表示されます。index.html from /mywebsite/
index.html from /mywebsite/Copy to Clipboard Copied! Toggle word wrap Toggle overflow