Fedora 15 で public_html を公開してみる。
PostgreSQL 関連の開発環境では SGML ドキュメントの変更確認用に httpd をあげているんですが、Fedora 15 に移行したらいろいろ設定が必要だったので整理。最近の Linux では標準的な、SE-Linux と iptables ありの環境での UserDir の使い方めも。
iptables
httpd を起動してもメインのドキュメントルートが閲覧できない。クライアント側が SYN_SENT になっていたのでファイアウォールだよね、と思い iptables のチェインに inbound HTTP/HTTPS を許可するエントリを追加しました。
[hanada@callisto ~]$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination [hanada@callisto ~]$ sudo iptables -I INPUT 4 -p tcp --dport http -j ACCEPT [hanada@callisto ~]$ sudo iptables -I INPUT 4 -p tcp --dport https -j ACCEPT [hanada@callisto ~]$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination [hanada@callisto ~]$ sudo service iptables save iptables: ファイアウォールのルールを /etc/sysconfig/iptable[ OK ]中: [hanada@callisto ~]$
これでめでたく Fedora Test Page にアクセス成功。
httpd
/etc/httpd/conf/httpd.conf を編集して、UserDir を有効化しました。
本筋ではないですが、最近使い慣れてきたので、git で版管理してみることに。
[hanada@callisto conf]$ cd /etc/httpd/conf [hanada@callisto conf]$ sudo git init Initialized empty Git repository in /etc/httpd/conf/.git [hanada@callisto conf]$ sudo git add httpd.conf [hanada@callisto conf]$ sudo vi httpd.conf ... [hanada@callisto conf]$ sudo git commit -a ... [hanada@callisto conf]$ sudo service httpd reload
これまではこれで公開できてたんですが、403 Forbidden に。そういえば Fedora のインストール中に SE-Linux の設定がなかったな、と思い確認。
[hanada@callisto conf]$ /usr/sbin/getenforce Enforcing
やっぱり SE-Linux が有効でした。
SE-Linux
httpd が読み取れるように、公開ディレクトリのセキュリティコンテキストを変更。Fedora 15 では public_html 用の定義済みコンテキストがあるので restorecon だけでいいので楽チンです。それと、ユーザディレクトリを公開するためにはセキュリティポリシーの変更が必要でした。
[hanada@callisto conf]$ restorecon -R $HOME/public_html [hanada@callisto conf]$ sudo setsebool httpd_enable_homedirs true
めでたく PostgreSQL のドキュメントが閲覧できました。