このエントリーをはてなブックマークに追加


Apacheで一般ユーザーの$HOME/public_htmlを公開する設定方法

Apacheの設定により、以下のようにユーザーごとのホームページを公開することができます。

http://サーバー名/~ユーザー名

これにより、サーバーに存在するユーザー毎にホームページを作成することができます。
以下、~ユーザー名によるホームページ公開の設定方法を記します。


スポンサーリンク

使用した環境

本資料で使用した環境は以下の通りです。

  • OS
    $ lsb_release -d
    Description:    CentOS release 6.3 (Final)
  • Apache
    $ 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を無効にする

SELinuxを無効にしないとPermission deniedになります。
SELinuxの無効化は以下のリンクを参考にして設定してください。

ちなみにrootユーザーになり、以下のコマンドでEnforceと出力されたらSELinuxが有効になっています。

[root@centos6 ~]# getenforce
Enforcing

一時的にSELinuxを無効化にする方法は、以下のコマンドで可能です。

setenforce 0

httpd.confを修正しユーザー毎にホームページを公開する

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>
  • 変更後
    以下の変更を行いました。
  1. userdir_moduleのロード(最初からコメントされていなかったのでそのまま。コメントされている場合は有効にしてください。)
  2. UserDir disabled → #UserDir disabled
  3. #UserDir public_html → UserDir public_html
  4. <Directory /home/*/public_html> ... </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)を再起動します。
    CentOSではrootユーザーにて以下のコマンドで再起動しました。
    service httpd restart
    上記コマンドを実行したときの出力です。
    [root@centos6 ~]# service httpd restart
    httpd を停止中:                                            [  OK  ]
    httpd を起動中:                                            [  OK  ]
    [root@centos6 ~]#
     

ユーザーのホームディレクトリにpublic_htmlを作成する

以下、ユーザー名 sakura で設定を行います。

  1. sakura ユーザーでログインします。
  2. public_htmlディレクトリを作成します。
    mkdir ~/public_html
  3. httpd(apache)プロセスがアクセスできるようにパーミッションを設定します。
    CentOSの設定を見たところ、以下のようになっていました。
    [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を作成しブラウザからアクセスしてみる

作成した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/

実際にアクセスしたときのスクリーンショットです。

01.gif

以上、Apacheで一般ユーザーの$HOME/public_htmlを公開する設定方法でした。


スポンサーリンク

添付ファイル: file01.gif 795件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-03-20 (金) 22:35:47