最終更新日 : Saturday, 06-May-2006 00:11:10 JST
RedHat Linux9やFedoraCoreなどのバージョンのLinuxでは,Apacheなどの主要なアプリケーションはRPMというパッケージでインストール・アンインストールできます。ここでは,LinuxインストールCDに収録されているApacheについて説明をします。
Apacheの設定はhttpd.confという設定ファイルを書き換えることによって行うことが出来ます。ここでは,この設定ファイルの説明を簡単に行っていきます。
なお,httpd.confは標準では/etc/httpd/conf/httpd.confに収められています。httpd.confを編集したら,設定を反映するためにApacheを再起動しましょう。
#/etc/init.d/httpd restart |
他のサイトではこのhttpd.confを日本語訳しているところもあります。参考になさってください。
以上の設定で,最低限の設定はOKです。
補足,SSL対応サイトを強制的にSSLサイトへ向かわせる方法。
SSL対応サイトとそうでないサイトを同一サーバー上で運用すると,SSL対応にしたいサイトへSSL対応していない方法で接続する可能性が生じます。
(例:https://yourdomain.com/ssl/が本来のアドレスだが,
http://yourdomain.com/ssl/
で接続してしまう。)このようなことは,セキュリティーホールになりうるので,http://〜で接続してきたときはhttps://〜へリダイレクトするように設定します。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog "logs/rewrite_log"
RewriteLogLevel
0
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/webmail/(.*)?$
https://%{HTTP_HOST}/webmail/$1 [L,R]
RewriteRule ^/postmail/ssl/(.*)?$
https://%{HTTP_HOST}/postmail/ssl
$1 [L,R]
</IfModule>
この設定例だと,http://yourdomai.com/webmail/〜のアドレスとhttp://yourdomai.com/postmail/ssl/〜のアドレスをhttps://〜のサイトへ誘導することになります。
実際に,このサーバで使用している設定ファイルの一部である。デフォルトで用意されている設定ファイルから変更しある部分を一部取り出してみた。
コメントを書き加えたので,参考にして頂きたい。
# # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # #KeepAliveをOnにすると,リクエストの処理が終了しても一定時間接続を保つ。 #複数のファイルを一度に取るときは,処理時間が短くなるのでOnがおすすめ。 KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. #この値は,サーバーを運用する場所によって変わるが通常はそのままでよい。 MaxKeepAliveRequests 100 # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, in addition to the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses (0.0.0.0) # #Listen 12.34.56.78:80 #通常は80番ポートを使用する。特別な場合は変更する。 Listen 80 # # ServerAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. admin@your-domain.com # #エラーメッセージなどに表記されるwebmasterへのメールアドレスをここに書く。 ServerAdmin kei_kun@email.plala.or.jp # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If this is not set to valid DNS name for your host, server-generated # redirections will not work. See also the UseCanonicalName directive. # # If your host doesn't have a registered DNS name, enter its IP address here. # You will have to access it by its address anyway, and this will make # redirections work in a sensible way. # #運用する場所のドメイン名を書く。 ServerName keikun.homeip.net:80 # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # #ドキュメントルートを指定する。ここがサーバのトップページになる。 DocumentRoot "/home/www/public_html" # # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. # # The path to the end user account 'public_html' directory must be # accessible to the webserver userid. This usually means that ~userid # must have permissions of 711, ~userid/public_html must have permissions # of 755, and documents contained therein must be world-readable. # Otherwise, the client will only receive a "403 Forbidden" message. # # 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 able # # 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: # /~user/ でアクセスするには,/home/user/public_html/にコンテンツを置けばよい。 #ただし,/home, /home/userに,その他ユーザに実行権を, #/home/user/public_html に読み取り権限を与えないといけない。 UserDir public_html </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_html> # Dav On # AuthType Basic # AuthUserFile /etc/httpd/conf/.htpasswd # AuthGroupFile /dev/null AllowOverride All XBitHack on Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGI IncludesNoExec # <LimitExcept GET HEAD OPTIONS> # Require valid-user # </LimitExcept> </Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # # The index.html.var file (a type-map) is used to deliver content- # negotiated documents. The MultiViews Option can be used for the # same purpose, but it is much slower. # #リクエストが/などでディレクトリが指定されたとき自動補完するファイル名を列挙する。 #もしここに挙げるファイルがなければ,ファイル一覧や401エラーをはき出す。 DirectoryIndex index.html index.htm index.php # # AccessFileName: The name of the file to look for in each directory # for access control information. See also the AllowOverride directive. # #ディレクトリにおいてオプション設定を上書きするファイル名の指定 AccessFileName .htaccess # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. #.htから始まるファイルのアクセスを禁止する。 <Files ~ "^\.ht"> Order allow,deny Deny from all </Files> # # LanguagePriority allows you to give precedence to some languages # in case of a tie during content negotiation. # # Just list the languages in decreasing order of preference. We have # more or less alphabetized them here. You probably want to change this. # #jaを頭に持ってくる方が良いという話があるが,エラーメッセージは日付まで #英語で出た方がかっこいいので英語・日本語という順番 LanguagePriority en ja da nl et fr de el it kr no pl pt pt-br ltz ca es sv tw # # Specify a default charset for all pages sent out. This is # always a good idea and opens the door for future internationalisation # of your web site, should you ever want it. Specifying it as # a default does little harm; as the standard dictates that a page # 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. # #デフォルトの文字コードを設定する。デフォルトでは変なものになっているので #shift_jis にするか,コメントアウトして指定しないでおく。 #AddDefaultCharset shift_jis # # AddType allows you to add to or override the MIME configuration # file mime.types for specific file types. # #本サーバーではphpを動かしているのでphpの設定 # AddType application/x-tar .tgz AddType application/x-httpd-php .php # # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #本サーバーでは.plの拡張子のPerlスクリプトが動いているので.plを付け足す # AddHandler cgi-script .cgi .pl #旧Windowsサーバーではユーザディレクトリがチルダ(~)で始まらなかったため #旧アドレスで来た場合は新しいアドレスへリダイレクトするようにしてある。 Redirect permanent /kei/ http://keikun.homeip.net/~kei/ #メールフォームや,ウェブメーラーなど暗号化が望ましいページは #強制的にSSLを使用させる。 <IfModule mod_rewrite.c> RewriteEngine On RewriteLog "logs/rewrite_log" RewriteLogLevel 0 RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^/webmail/(.*)?$ https://%{HTTP_HOST}/webmail/$1 [L,R] RewriteRule ^/passwd/(.*)?$ https://%{HTTP_HOST}/passwd/$1 [L,R] RewriteRule ^/postmail/ssl/(.*)?$ https://%{HTTP_HOST}/postmail/ssl/$1 [L,R] </IfModule>
設定ファイルを変更した場合は忘れずにウェブサーバの再起動を。
#/etc/init.d/httpd restart
(c) 2000-2005 Kei All Rights Reserved.