fc2ブログ
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

Apache2の設定(前編) - Ubuntu9.04

今回の記事は以下の記事が前提条件となっています。


DefaultCharsetのコメント記号を除去してベース言語をUTF-8に設定する。
mitsuki@ubuntu:~$ gksudo gedit /etc/apache2/conf.d/charset

#AddDefaultCharset UTF-8
↓↓↓
AddDefaultCharset UTF-8


次にセキュリティ関連設定ファイルを変更していきます。まずはHTTPレスポンスヘッダのApacheバージョンを非表示にする。
mitsuki@ubuntu:~$ gksudo gedit /etc/apache2/conf.d/security

ServerTokens Full
↓↓↓
ServerTokens ProductOnly

Apacheが生成したドキュメント中の情報を抑制する。
ServerSignature On
↓↓↓
ServerSignature Off

クロスサイトトレーシング対策としてTraceEnableをOffにする。TraceEnableに関する詳細はgrinの勝手気ままに戯言メモさんが参考になります。
TraceEnable On
↓↓↓
TraceEnable Off


ディレクトリインデックスの設定。この設定変更は任意です。私の場合はPHPでサイトを構築することが多いのでindex.phpを先頭に移動させます。(検索する優先順位の変更)
mitsuki@ubuntu:~$ gksudo gedit /etc/apache2/mods-enabled/dir.conf

<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
↓↓↓
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>


言語の優先順位を変更。
mitsuki@ubuntu:~$ gksudo gedit /etc/apache2/mods-enabled/negotiation.conf

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv tr zh-CN zh-TW
↓↓↓
LanguagePriority ja en ca cs da de el eo es et fr he hr it ko ltz nl nn no pl pt pt-BR ru sv tr zh-CN zh-TW


CGIが使えるようにする。
mitsuki@ubuntu:~$ gksudo gedit /etc/apache2/mods-enabled/mime.conf

#AddHandler cgi-script .cgi
↓↓↓
AddHandler cgi-script .cgi .pl


サイト定義ファイルの作成。
mitsuki@ubuntu:~$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/hogehoge <- デフォルトのサイト定義をコピーして新たなサイト定義を作成
mitsuki@ubuntu:~$ gksudo gedit /etc/apache2/sites-available/hogehoge <- 新たに作成したサイト定義を編集

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
↓↓↓
<FilesMatch "(^\.ht|~$|\.bak$|\.BAK$)"> #.htaccessや.bak等の意図しないファイルの閲覧を抑制
Order allow,deny
Deny from all
</FilesMatch>

<Directory /var/www/>
Options FollowSymLinks MultiViews #ファイル一覧が表示されないようにする
AllowOverride All #.htaccessでの設定上書きを許可する
Order allow,deny
allow from all
</Directory>


デフォルトのサイト定義を無効にして、新しく作成したサイト定義を有効にする。
mitsuki@ubuntu:~$ sudo a2dissite default && sudo a2ensite hogehoge
Site default disabled.
Run '/etc/init.d/apache2 reload' to activate new configuration!
Enabling site hogehoge.
Run '/etc/init.d/apache2 reload' to activate new configuration!


mod_rewriteを有効にする。
mitsuki@ubuntu:~$ sudo a2enmod rewrite
Enabling module rewrite.
Run '/etc/init.d/apache2 restart' to activate new configuration!


最後にApache2を再起動。
mitsuki@ubuntu:~$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]

※Apache2を再起動した時に表示される警告は放置して問題ない。「でも気になる!」という人はApacheのwarning回避UbutnuでApache2を起動してみたを参考にすると幸せになれます。

コメント

コメントを投稿する

管理者にだけ表示を許可する

トラックバック

検索フォーム
カテゴリ
カレンダー
02 ≪│2025/03│≫ 04
- - - - - - 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 - - - - -
最新記事
リンク