Apacheの設定により、以下のようにユーザーごとのホームページを公開することができます。
http://サーバー名/~ユーザー名
これにより、サーバーに存在するユーザー毎にホームページを作成することができます。
以下、~ユーザー名によるホームページ公開の設定方法を記します。
本資料で使用した環境は以下の通りです。
$ lsb_release -d Description: CentOS release 6.3 (Final)
$ httpd -v Server version: Apache/2.2.15 (Unix) Server built: Feb 13 2012 22:31:42
本環境以外の方(Windowsなど)でも、httpd.confは一緒なので、本資料に記述してあるディレクトリなどを読み替えて使用してください。
また、httpd.confではなく、apache.confになっている環境もあると思いますのでご注意ください。
Windows, CentOS, UbuntuのLAMP, LAPPなどのインストール使用を公開しています。 参考にしてください。
以下の4つの資料はLINUX.JUST4FUN.BIZで公開している資料です。
SELinuxを無効にしないとPermission deniedになります。
SELinuxの無効化は以下のリンクを参考にして設定してください。
ちなみにrootユーザーになり、以下のコマンドでEnforceと出力されたらSELinuxが有効になっています。
[root@centos6 ~]# getenforce Enforcing
一時的にSELinuxを無効化にする方法は、以下のコマンドで可能です。
setenforce 0
httpd.confファイルを開き、以下のキーワードを探します。
本資料では、CentOS6を使用しています。
以下のディレクトリにhttpd.confがありました。
作業はrootユーザーにて行いました。
[sakura@centos6 ~]$ su - パスワード: [root@centos6 ~]# vi /etc/httpd/conf/httpd.conf
187 LoadModule userdir_module modules/mod_userdir.so <省略> 360 <IfModule mod_userdir.c> 361 # 362 # UserDir is disabled by default since it can confirm the presence 363 # of a username on the system (depending on home directory 364 # permissions). 365 # 366 UserDir disabled 367 368 # 369 # To enable requests to /~user/ to serve the user's public_html 370 # directory, remove the "UserDir disabled" line above, and uncomment 371 # the following line instead: 372 # 373 #UserDir public_html 374 375 </IfModule> <省略> 381 #<Directory /home/*/public_html> 382 # AllowOverride FileInfo AuthConfig Limit 383 # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec 384 # <Limit GET POST OPTIONS> 385 # Order allow,deny 386 # Allow from all 387 # </Limit> 388 # <LimitExcept GET POST OPTIONS> 389 # Order deny,allow 390 # Deny from all 391 # </LimitExcept> 392 #</Directory>
187 LoadModule userdir_module modules/mod_userdir.so <省略> 360 <IfModule mod_userdir.c> 361 # 362 # UserDir is disabled by default since it can confirm the presence 363 # of a username on the system (depending on home directory 364 # permissions). 365 # 366 #UserDir disabled 367 368 # 369 # To enable requests to /~user/ to serve the user's public_html 370 # directory, remove the "UserDir disabled" line above, and uncomment 371 # the following line instead: 372 # 373 UserDir public_html 374 375 </IfModule> <省略> 381 <Directory /home/*/public_html> 382 AllowOverride FileInfo AuthConfig Limit 383 Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec 384 <Limit GET POST OPTIONS> 385 Order allow,deny 386 Allow from all 387 </Limit> 388 <LimitExcept GET POST OPTIONS> 389 Order deny,allow 390 Deny from all 391 </LimitExcept> 392 </Directory>変更が終了したらhttpd.confを保存しapache(httpd)を再起動します。
service httpd restart上記コマンドを実行したときの出力です。
[root@centos6 ~]# service httpd restart httpd を停止中: [ OK ] httpd を起動中: [ OK ] [root@centos6 ~]#
以下、ユーザー名 sakura で設定を行います。
mkdir ~/public_html
[sakura@centos6 ~]$ cd .. [sakura@centos6 home]$ ls -l 合計 8 drwx------. 30 sakura sakura 4096 2月 11 21:00 2013 sakura drwx------. 4 tsubaki tsubaki 4096 2月 11 21:03 2013 tsubakiユーザー以外、アクセスができないので、以下のようにパーミッションを変更しました。
chmod o+r /home/sakura以下、chmodによるアクセス権限変更および確認を記します。
[sakura@centos6 home]$ pwd /home [sakura@centos6 home]$ ls -ld sakura/ drwx------. 30 sakura sakura 4096 2月 11 21:00 2013 sakura/ [sakura@centos6 home]$ chmod o+x sakura/ [sakura@centos6 home]$ ls -ld sakura/ drwx-----x. 29 sakura sakura 4096 2月 11 21:21 2013 sakura/その他にパーミッション(権限)に--xになりました。
上記操作で作成したpublic_htmlのパーミッションを確認すると以下のようにその他のr(リード)になっていたので特に設定は行いませんでした。
[sakura@centos6 home]$ cd [sakura@centos6 ~]$ ls -ld public_html/ drwxrwxr-x. 2 sakura sakura 4096 2月 11 21:02 2013 public_html/
作成したpublic_htmlディレクトリにindex.htmlを作成してみます。
[sakura@centos6 ~]$ cd public_html/ [sakura@centos6 public_html]$ echo '<b>Hello world!</b>' > index.html
作成したindex.htmlのパーミッションを確認すると、その他にr(リード)権限があるので特に変更しませんでした。
[sakura@centos6 public_html]$ ls -l index.html -rw-rw-r--. 1 sakura sakura 20 2月 11 21:14 2013 index.html
今回使用したユーザー名はsakuraです。
したがって、以下のようにすれば/home/sakura/public_html/のindex.htmlにアクセスが可能です。
http://ホスト名/~sakura/
実際にアクセスしたときのスクリーンショットです。
以上、Apacheで一般ユーザーの$HOME/public_htmlを公開する設定方法でした。