設定ファイル

各ファイル

httpd.conf設定の中心となるファイル。小さいサイトであればこのファイルだけに完結させた方が楽
magic拡張子以外によるMIMEタイプの設定をするファイル

2.4以降のアクセス制限

特定ホスト or IPだけ

           Require all denied
           # from xxx.hogehoge.ne.jp
           Require host .hogehoge.ne.jp
           # IP
           Require ip xxx.xxx.xxx.xxx

Apacheモジュール

mod_rewrite

サーバー移転などのURLリダイレクトや動的ページをHTMLに見せるなどの用途で使われる。

RewriteEngine on
RewriteRule ^from/(.+)$ to/$1 [R=301,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule book([0-9a-zA-Z_\-]+).html$ http://sample.com /test/index.php?bookid=$1 [L]

参考サイト

http://blog.dawgsdk.org/weblog/archives/411011

Tomcatとの連携

#By TF
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
<Location /任意の名前/>
  ProxyPass /jenkins ajp://サーバーのIP:8009/コンテキスト名/
  # 302の時に必要。
  ProxyPassReverse /jenkins ajp://サーバーのIP:8009/コンテキスト名/
</Location>

認証

.htaccessを使う場合のパフォーマンス上の留意点

AllowOverride AuthConfigとすると毎回.htaccessファイルを探しにいくので利用しない場合はNoneにしておく

BASIC認証

<Directory "制限したいディレクトリ">
      AuthUserFile conf/.htpasswd
      AuthName "hogehoge"
      AuthType Basic
      require valid-user
</Directory>
<Direcotry>
   AllowOverride AuthConfig
</Directory>
AuthUserFile conf/.htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user

/usr/local/apache2/bin/htpasswd -c .htpasswd USER

Digest認証

http://www.atmarkit.co.jp/flinux/rensai/linuxtips/699apachedigest.html

このページのとおりにやったら一部情報が古くてはまった。

Invalid command 'AuthDigestFile', perhaps misspelled or defined by a module not included in the server configuration

AuthDigestFileというのはBASIC認証と同じAuthUserFileに統一されたようだ。

httpd.confへの設定

<Directory "/var/www/html/">
   AuthType Digest
   AuthName "Secret Zone"
   AuthDigestDomain /personal/
   AuthUserFile /etc/httpd/conf/.htdigest
   Require user secret
</Directory>

AuthNameは単なるダイアログ表示だけの存在ではなく、次のユーザ作成の時に一致させる必要があるので注意。

パスワードファイルの作成

htdigest -c /etc/httpd/conf/.htdigest 'Secret Zone' secret

各設定の優先順位

http://hegel.aichi-u.ac.jp/manual/sections.html

特定のネットワークからは認証させない

公式サイトより引用

Require valid-user
Allow from 192.168.1
Satisfy Any 
<Directory "/vaw/www/html/staffonly">
    Order allow,deny
    Allow from all
    Deny from 192.168.1.0/24

    AuthType Basic
    AuthName "INPUT YOUR ID AND PASSWORD"
    AuthUserFile "conf/.htpasswd"
    Require valid-user
    Satisfy any
</Directory>

トラブルシューティング

403が出る時

拡張子制限などの時

[Sun Apr 12 12:35:34.194759 2020] [access_compat:error] [pid 14267] [client 162.158.118.47:41326] AH01797: client denied by server configuration: /var/www/vhosts/blog/wp-config.php
Counter: 5222, today: 1, yesterday: 2

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-10-14 (金) 13:16:52