ICON of RYUUO.COM TradeMark

Apacheの設定

会員登録(SSL)
会員専用(SSL)


更新日: 2006/10/17


Apacheの設定(httpd.conf)

FedoraCore3のhttpd-2.0.52-3.1 についての記述です。詳細に付いての記述ではなくガイダンス的一般論と理解して下さい。今後、詳細に付いて解説してあるページのリンクは出来るだけ記述していくつもりです。
また、httpdを初めて起動する場合にはファイアウォールとセキュリティの設定(WWW)を許した後、iptablesを再起動しなければならない。
ここのページでの主な説明
  • http://localhost/ でプラウザに表示させる。
  • Directory毎の大まかな説明.....LogFile.CGI.Accessなどに 関する設定
  • userminやtomcatなどを利用するときのProxyServerの設定




    • 次は、デーモンの設定・・・メインメニューからプログラム/システム/サービス設定を選び httpdにチェックをいれておく
    • 次は、/etc/httpd/conf/httpd.confの編集です(ディストリビューションによっては httpd.confの場所は違う)・・・httpd.confは Section 1・Section 2・Section 3から成り立っています。


    ServerNameについて
    Section 2 の(260行目/約1100行中 あたり)

    # You will have to access it by its address anyway, and this will make
    # redirections work in a sensible way.
    #
    #ServerName new.host.name:80
    ServerName localhost:80
    サーバを建てた時は実際の名前を(ex....  host.example.com:80)
    それ以外の時も機種名を付けておきましょう。
    ex)...aptiva:80
    ServerName aptiva:80
    家庭内の他のパソコンのプラウザから http://aptiva/ として接続してみましょう。もちろん、hosts fileの設定も必要ですが。詳細については家庭内Lanを参照下さい。

    #
    # UseCanonicalName: Determines how Apache constructs self-referencing
    # URLs and the SERVER_NAME and SERVER_PORT variables.

    DocumentRoot " /var/www/html " について
    Section 2 の(270行目/約1100行中 あたり)

    # symbolic links and aliases may be used to point to other ...
    #
    DocumentRoot " /var/www/html "
    /var/www/htmlはサーバにした時のトップページのディレクトリです。プラウザでhttp://localhost/で表示される場合のhtml文は/var/www/html/index.htmlです。

    #
    # Each directory to which Apache has access, can be configured ...
    # to which services and features are allowed and/or disabled in ...
    # directory (and its subdirectories).
    #
    # First, we configure the " default " to be a very restri....
    # permissions.
    #

    < Directory " /var/www/html " >
    /var/www/html(DocumentRoot directory以下の条件を、例として、cgi・他のプログラムの動作を有効・無効にするかの設定、クライアントからのアクセスの制御...等々)の条件を設定する

    # # Possible values for the Options directive are " None ", " All" ,
    # or any combination of:
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that " MultiViews " must be named *explicitly* --- " Options All "
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important. Please see
    # http://httpd.apache.org/docs-2.0/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be " All ", " None ", or any combination of the keywords:
    # Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
    < /Directory >
    Allow from all はすべてからアクセスを許可する設定です。
    アクセスしてもらいたくないアドレスがあればここに記述する。
    ORDER BY allow deny
    allow from all
    deny from 192.168.1.101
    deny from host.example.com
    のように、サーバ攻撃して来るIPアドレスがあればアクセス不許可に出来る。
    私の場合、ネチッコくサーバ攻撃して来るアドレスがあったので一月程度
    某大国のプロバイダ(Bクラス)からのアクセスを拒否していた。
    自宅サーバのできる業でしょうか...?

    ただ、この設定だとどの程度のアクセス量がきているのか判別できないのであまり好ましい対処方法とは思えない。もし、ゆとりのある方は、また、興味のある方は TCP/IP段階でDROP REJECTさせる方法があるのでその方面を考えてもよいだろう。難しいことをいうと、インターネットのなかを流れて来るときに大きなファイルは分割されて送られて来る。
    # ifconfig -a

    で表示される MTU:****の数字が最大量だ。それ以上になると分割されてくることになる。そのパケット(小包のような物)がトランスポート層(OSの一部分)を通過するときに弾く方法であり、Netfilterとかiptables とかいう単語で検索すればヒットすると思う。こちらの方がcpuへの負荷が少ないであろう。




    ユーザにホームページの公開を許可・不許可の設定
    Section 2 の(340行目/約1100行中 あたり)

    # See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden
    #
    < IfModule mod_userdir.c >
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir disable
    全てのユーザにホームページの公開を不許可にする時は
    UserDir publicのコメントを外す

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    #
    # UserDir public
    全てのユーザにホームページの公開を許可する時は
    UserDir publicのコメントを外す
    < /IfModule >


    #
    # Control access to UserDir directories. The following is an example
    # for a site where these directories are restricted to read-only.
    #
    < Directory /home/*/public >
      AllowOverride FileInfo AuthConfig Limit
      Options MultiViews Indexes SymLinksIfOwnerMatch
      < Limit GET POST OPTIONS >
        Order allow,deny
        Allow from all
      < /Limit >
      < LimitExcept GET POST OPTIONS >
        Order deny,allow
        Deny from all
      < /LimitExcept>
    < /Directory >

    # HomeDirectoryでのCGIの使用について...確認はしていないが
    # 参照:
    # http://httpd.apache.org/docs/2.0/howto/public_html.html



    Section 2 の(およそ450行目/約1100行中 あたり)
    
    error_logに... core_output_filter: writing data to the network 表示された。
    
    
    #
    # EnableMMAP: Control whether memory-mapping is used to deliver
    # files (assuming that the underlying OS supports it).
    # The default is on; turn this off if you serve from NFS-mounted 
    # filesystems.  On some systems, turning it off (regardless of
    # filesystem) can improve performance; for details, please see
    # http://httpd.apache.org/docs-2.0/mod/core.html#enablemmap
    #
    #EnableMMAP off
    EnableMMAP off
    
    #
    # EnableSendfile: Control whether the sendfile kernel support is 
    # used to deliver files (assuming that the OS supports it). 
    # The default is on; turn this off if you serve from NFS-mounted 
    # filesystems.  Please see
    # http://httpd.apache.org/docs-2.0/mod/core.html#enablesendfile
    #
    #EnableSendfile off
    EnableSendfile off
    
     
    以上の設定でも表示されるときは、
    考えられる理由として:
    1)alias の設定の間違い
      Alias /icons/ "/var/www/icons/"
      
      Alias /icons/ "/var/www/icons"
    
    2) 不正アクセスなどの接続によりエラーログに残ることがある。
       apacheの問題では無い
    
    
    
    LogFileの取り方の設定
    Section 2 の(490行目/約1100行中 あたり)

    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    LogFormat "%{Referer}i -> %U" referer
    LogFormat "%{User-agent}i" agent

    ログファイルのファーマット形式はhttp://httpd.apache.org/docs/2.0/logs.html

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a


    /var/log/httpdディレクトリ内のlog_fileのログの取り方(formatの設定)を決定する。ログファイルを眺めてみるとメガ単位の攻撃がログを汚していた。 最初のうちはアクセスしてくるほとんどはサーバ攻撃だけのアクセスでろう。

    不正アクセスのログが時々残っている。
    [28/Feb/2006:19:55:41 +0900] "CONNECT http://www.example.com/index.html" 501 497 "-" "-"

    実験を試みる。telnetを有効にする。ただし、他人様のサーバにアクセスすると不正アクセスなどで問題になるので注意が必要だ。
    $ telnet localhost 80
     Trying 127.0.0.1...
     Connected to localhost.localdomain (127.0.0.1).
     Escape character is '^]'.
     GET / HTTP/1.1
     Content-type: text/html
     Connection: KeepAlive
     Referer: http://example.com/
     User-Agent: Mozilla/5.0 (compatible; himajinn/0.1)
     Host: localhost
     <---改行を入れる
     ------- 略 ------
     <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
     <html><head>
     <t	 
     ------- 略 ------
    $
    
    ログファイルの内容
    127.0.0.1 - - [05/Jan/2008:14:10:56 +0900] "GET / HTTP/1.1" 503 397 "http://example.com
    /" "Mozilla/5.0 (compatible; himajinn/0.1)"
    
    GETのかわりにPOST CONNECTなどのコマンドが利用できる。また、telnetを不可にしてもProgram
    でtcpを利用してアクセスしてくるので注意が必要だ。Referer:の部分に見慣れぬURLがある場合には
    Programによりアクセスしてきていると解釈もできる。
    この世界は油断も隙もない世界だ。
    	 






    文字化け解消
    Section 2 の(787行目/約1044行中 あたり)

    # is in iso-8859-1 (latin1) unless specified otherwise i.e. you
    # are merely stating the obvious. There are also some security
    # reasons in browsers, related to javascript and URL parsing
    # which encourage you to always set a default char set.
    #
    AddDefaultCharset UTF-8

    #
    AddDefaultCharset UTF-8の部分をコメント化する。
    # AddDefaultCharset UTF-8
    文字化けを防ぐ






    cgiを使用する時の設定
    Section 2 の(600行目/約1100行中 & 830行目/約1100行中 あたり)


    600行目/約1100行...
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    #
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    Alias /images/ "/var/www/images/"
    cgi-bin ディレクトリ内に画像ファイルを置いても表示されないので
    Aliasを設定して、そこにcgiスクリプトで使用する画像を置く。
    cgiスクリプト内での使用は<BODY BACKGROUND=\"images/temp.png\">のような感じ
    #
    # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.

    830行目/約1100行中...
    # If you want to use server side includes, or CGI outside
    # ScriptAliased directories, uncomment the following lines.
    #
    # To use CGI scripts:
    #
    #AddHandler cgi-script .cgi
    AddHandler cgi-script .cgi
    cgiを使用する時は#を外す
    #
    # To use server-parsed HTML files
    #





    Proxy Serverの使用時の設定
    Section 2 の(930行目/約1100行中 あたり)

    #
    # Proxy Server directives. Uncomment the following lines to
    # enable the proxy server:
    #
    <IfModule mod_proxy.c>
    ProxyRequests On
    SSLProxyEngine On -->https://localhost....を使用する場合は必須

    <Proxy *>
      Order allow,deny
      Allow from all
      Deny from all
    # Deny from .example.com
    </Proxy>
    #
    # Enable/disable the handling of HTTP/1.1 " Via:" headers.
    # ("Full" adds the server version; " Block" removes all outgoing Via: headers)
    # Set to one of: Off | On | Full | Block
    #
    ProxyVia Block
    #
    # To enable a cache of proxied content, uncomment the following lines.
    # See http://httpd.apache.org/docs-2.0/mod/mod_cache.html for more details.
    #
    <IfModule mod_disk_cache.c>
      CacheEnable disk /
      CacheRoot " /var/cache/mod_proxy"
    </IfModule>
    </IfModule>
    # End of proxy directives.

    ProxyPass /usermin/ https://localhost:20000/
    ProxyPassReverse /usermin/ https://localhost:20000/
    ProxyPass /tomcat/ http://localhost:8080/
    ProxyPassReverse /tomcat/ http://localhost:8080/

    これで、GUIでのサーバ構築を考えている方にはwebmin & userminを、
    また、動的コンテンツを考えている方にはtomcatを利用できるようになる。
    http://localhost/usermin/
    http://localhost/tomcat/
    で、表示できるようになる。
    ただ、プロキシを利用した場合にはサーバ攻撃が非常に多くなるので、踏み台にされたくなければプロキシを利用しない連携を考えるべきだ。下記アドレスを参考に。
    http://www.ryuuo.com/Services/search/
    から検索してもらいたい。






    httpd.confを更新した時はhttpdの再起動
    # /etc/rc.d/init.d/httpd restart
    or
    # /sbin/service httpd restart
    or
    # su -
    # service httpd restart
    を行って下さい。

    余計なことを、もう一点。家庭内LANを構築することにより、自宅の他のコンピュータから Linux機のwebサーバに接続することも出来ます。自宅サーバを構築するための勉強にもなります。家庭内LANを構築したい方は 『家庭内LAN構築に関して』を御覧下さい。