|  |  |  |  | 
                
                  | サーバー通信データ圧縮化(Apache2 + mod_deflate) | 
                
                  |  |  |  |  | 
                
                  | ● | Apace2設定ファイル編集 |  |  | 
                
                  |  | # vi /etc/apache2/conf/httpd.conf
 
 LoadModule deflate_module modules/mod_deflate.so の記述有無確認
 ?mod_deflate.so   ?コマンドでmod_deflate.soを検索
 
 SetOutputFilter DEFLATE   追記(DEFLATEを有効化)
 DeflateCompressionLevel 5   追記(圧縮レベルを指定(低1〜9高))
 BrowserMatch ^Mozilla/4 gzip-only-text/html   追記(ブラウザがNetscape 4.xの場合はtext/htmlのみ圧縮)
 BrowserMatch ^Mozilla/4\.0[678] no-gzip   追記(ブラウザがNetscape 4.06-4.08の場合は圧縮しない)
 BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html   追記(ブラウザがMSIEの場合は全て圧縮)
 Header append Vary User-Agent env=!dont-vary   追記(圧縮未対応ブラウザへは圧縮ファイルを送信しない)
 
 以下ログ取得の記述
 DeflateFilterNote Input instream
 DeflateFilterNote Output outstream
 DeflateFilterNote Ratio ratio
 LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%) %{User-agent}i' deflate
 CustomLog logs/deflate_log deflate
 
 編集終了 保存
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | Apace2再起動 |  |  | 
                
                  |  | # /etc/rc.d/init.d/apache2 restart
 
 Apache2 HTTP Serverを停止中:                [ OK ]
 Apache2 HTTP Serverを起動中:                [ OK ]
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | データ圧縮の確認 |  |  | 
                
                  |  | ログの確認
 # tail /var/log/apache2/deflate_log
 
 "GET / HTTP/1.1" -/- (-%) Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
 "GET /browserconfig.
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  |  |  |  |  | 
                
                  | http://ドメイン/~ユーザー名でアクセスできるようにする | 
                
                  | ● | Apace2設定ファイル編集 |  |  | 
                
                  |  | # vi /etc/apache2/conf/httpd.conf
 
 #UserDir disable      # を追記(コメントアウト)
 UserDir public_html     # を削除
 
 以下の分部の#を削除
 <Directory /home/*/public_html>
 AllowOverride FileInfo AuthConfig Limit
 Options MultiViews SymLinksIfOwnerMatch IncludesNoExec    Indexesを削除
 <Limit GET POST OPTIONS>
 Order allow,deny
 Allow from all
 </Limit>
 <LimitExcept GET POST OPTIONS>
 Order deny,allow
 Deny from all
 </LimitExcept>
 </Directory>
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | ユーザーのCGI専用ディレクトリの設定 |  |  | 
                
                  |  | /etc/apache2/conf/httpd.confの編集続行 |  |  | 
                
                  |  | ScriptAliasにURLパス(/cgi_bin/など) 、ディレクトリ名(/home/httpd/cgi_bin/など)を指定する
 (CGIを許可するディレクトリは複数指定可能)
 以下の設定の場合、CGIディレクトリは、各ユーザーディレクトリ毎に異なったディレクトリ名(cgi_bin0、cgi-bin、cgi_bin等)にしないとapache起動エラーになるようです。
 
 #ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"     # を追記(コメントアウト)
 ScriptAlias /cgi_bin0/ /home/httpd/cgi_bin0/     追記(こちらはcgi_bin0)
 ScriptAlias /cgi-bin/ /home/ユーザー1ディレクトリ/public_html/cg-bin/   追記(ユーザー1はcgi-bin)
 ScriptAlias /cgi_bin/ /home/ユーザー2ディレクトリ/public_html/cg_bin/   追記(ユーザー2はcgi_bin)
 
 以下をコメントアウト
 #<Directory "/var/www/cgi-bin">
 #    AllowOverride None
 #    Options None
 #    Order allow,deny
 #    Allow from all
 #</Directory>
 
 
 以下を追記
 /home/httpd/cgi_bin0でCGIを使えるようにする
 <Directory /home/httpd/cgi_bin0>    ScriptAliasの指定に合わせる
 AllowOverride None
 Options ExecCGI    CGIを有効にする
 Order allow,deny
 Allow from all
 </Directory>
 
 
 ユーザー1ディレクトリ/public_html/cgi-binでCGIを使えるようにする
 <Directory /home/ユーザー1ディレクトリ/public_html/cgi-bin>   ScriptAliasの指定に合わせる
 AllowOverride FileInfo AuthConfig Limit
 Options ExecCGI   CGIを有効にする
 Order allow,deny
 Allow from all
 </Directory>
 
 
 ユーザー2ディレクトリ/public_html/cgi_binでCGIを使えるようにする
 <Directory /home/ユーザー2ディレクトリ/public_html/cgi_bin>   ScriptAliasの指定に合わせる
 AllowOverride FileInfo AuthConfig Limit
 Options ExecCGI   CGIを有効にする
 Order allow,deny
 Allow from all
 </Directory>
 
 
 編集終了 保存
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | Apache2再起動 |  |  | 
                
                  |  | # /etc/rc.d/init.d/apache2 restart
 
 Apache2 HTTP Serverを停止中:                [ OK ]
 Apache2 HTTP Serverを起動中:                [ OK ]
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  |  |  |  |  | 
                
                  | バーチャルホスト(http://ユーザー名.ドメインで接続する)設定 | 
                
                  |  |  |  |  | 
                
                  | ● | Apace2設定ファイル編集 |  |  | 
                
                  |  | # vi /etc/apache2/conf/httpd.conf 
 ServerName www.xxmainxx.com      追記(メインのドメイン名)
 NameVirtualHost *:80      追記
 
 メインのドメイン設定
 -----------------------------!注意-----------------------------------------------
 NameVirtualHost *:80   として
 <VirtualHost *:80>    とすること
 :80を入れないで*のままだと、Apache2起動時下記エラーが発生する
 OKが出るのでOKかと思うとOKではないApache2は起動していないのです
 Apache2 HTTP Serverを起動中: [Mon Jul 14 14:28:46 2014] [error] VirtualHost
                  _default_:443
 -- mixing ports and non-* ports with a NameVirtualHost address is not
                  supported, proceeding with undefined rsults
 [ OK ]
 -----------------------------------------------------------------------------------
 以下を追記
 <VirtualHost *:80>
 ServerName www.xxmain1xx.com   メインのドメイン名(www.xxmain1xx.comは自分のドメイン)
 DocumentRoot /home/httpd/html   メインのディレクトリ
 HostNameLookups double
 UseCanonicalName off
 </VirtualHost>
 
 1つのメインディレクトリに対して複数のドメインを使用する場合は設定(追記)
 (私の環境では訳あって必要ですが一般的には不要と思われます)
 <VirtualHost *:80>
 ServerName www.xxmain2xx.net   別のメインのドメイン名(www.xxmain2xx.netは自分のドメイン)
 DocumentRoot /home/httpd/html   メインのディレクトリ
 HostNameLookups double
 UseCanonicalName off
 </VirtualHost>
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | ユーザーのドメインをバーチャルホストで接続する |  |  | 
                
                  |  | http://www.example.com/をユーザーディレクトリ home/example/public_html/に接続する。 |  | 
                
                  |  | http://www..example.com/で接続する場合
 <VirtualHost *:80>
 ServerName www.example.com     example.comはユーザーのドメイン
 DocumentRoot /home/example/public_html     exampleはユーザーのディレクトリ
 HostNameLookups double
 UseCanonicalName off
 </VirtualHost>
 
 
 http://example.com/で接続する場合
 <VirtualHost *:80>
 ServerName .example.com
 DocumentRoot /home/example/public_html
 HostNameLookups double
 UseCanonicalName off
 </VirtualHost>
 
 
 |  | 
                
                  |  | CGIは home/example/public_html/cgi_bin/ に置く。(私の設定です) |  | 
                
                  |  |  |  |  | 
                
                  | ● | バーチャルホスト、サブドメインの設定 |  |  | 
                
                  |  | /etc/apache2/conf/httpd.confの編集続行 |  |  | 
                
                  |  | ----------------- 参考 -------------------------------------------------------
 私の環境ではサブドメイン設定しない
 
 <VirtualHost *:80>
 ServerAdmin 1234@xxxxx.com
 DocumentRoot /home/ユーザー名/public_html    ドキュメントルート設定
 ServerName 1234.xxxxx.com     1234の部分はユーザーの任意
 </VirtualHost>
 
 他にもサブドメインがある場合は同様に追加する。
 -------------------------------------------------------------------------------
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | 1台のサーバーで複数のドメインを運用する設定 |  |  | 
                
                  |  | メインのドメインとは違うドメインで接続する場合の設定 (1つのサーバで複数のメインドメインを使う場合)
 |  |  | 
                
                  |  | /etc/apache2/conf/httpd.confの編集続行 |  |  | 
                
                  |  | <VirtualHost *:80>
 ServerName xxdomein3xx.info
 DocumentRoot /home/xx3xx/public_html     xx3xxはxxdomein3xx.infoのホームディレクトリ
 HostNameLookups double
 UseCanonicaiName off
 </VirtualHost>
 
 --------------------- 参考 -----------------------------------------------------
 サブドメインwww.を使う場合は追記する
 <VirtualHost *:80>
 ServerName www.xxdomein3xx.info
 DocumentRoot /home/xx3xx/public_html
 HostNameLookups double
 UseCanonicaiName off
 </VirtualHost>
 -------------------------------------------------------------------------------
 
 
 他にもドメインがある場合は同様に追加する。
 
 編集終了 保存
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | Apache2再起動 |  |  | 
                
                  |  | # /etc/rc.d/init.d/apache2 restart
 
 Apache2 HTTP Serverを停止中:                [ OK ]
 Apache2 HTTP Serverを起動中:                [ OK ]
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  |  |  |  |  | 
                
                  | ユーザーごとのApache2ログを取得する | 
                
                  | ● | 各ユーザー個別のログディレクトリ作製 |  |  | 
                
                  |  | 環境に応じて必要な場合は複数作成する
 
 # mkdir /var/log/apache2/xxmain2xx
 # mkdir /var/log/apache2/xxmain3xx
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | Apace2設定ファイル編集 |  |  | 
                
                  |  | # vi /etc/apache2/conf/httpd.conf
 
 /~ユーザー名 の場合下記を追記(私の環境の場合)
 -----この設定イマイチかなぁ Apacheエラーが出る(未解決)--------
 ~xxmain2xxを追記
 SetEnvIf Request_URI "/~xxmain2xx/" xxmain2xx nolog
 CustomLog logs/xxmain2xx/access_log combined env=xxmain2xx
 
 ~xxmain3xxを追記
 SetEnvIf Request_URI "/~xxmain3xx/" xxmain3xx nolog
 CustomLog logs/xxmain3xx /access_log combined env=xxmain3xx
 
 この設定今のところ中断中の為全てコメントアウトしている
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | Apache2のメインログの設定 |  |  | 
                
                  |  | 設定ファイル編集
 
 # vi /etc/logrotate.d/apache2
 
 /var/log/apache2/*log >
 daily       daily, weekly, monthlyのいずれかを指定
 rotate 14    履歴の数を指定
 missingok
 notifempty
 sharedscripts
 postrotate
 /bin/kill -HUP `cat /var/run/apache2.pid 2>/dev/null` 2> /dev/null || true
 endscript
 }
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | ユーザー用のログ設定 |  |  | 
                
                  |  | 引き続き/etc/logrotate.d/apache2の編集 |  |  | 
                
                  |  | 以下を追記する
 /var/log/apache2/*/*log {
 daily       毎日
 rotate 14     14日間
 missingok
 notifempty
 sharedscripts
 postrotate
 /bin/kill -HUP `cat /var/run/apache2.pid 2>/dev/null` 2> /dev/null || true
 endscript
 }
 
 編集終了 保存
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  | ● | ログファイル末尾の日付を1からの連番にする |  |  | 
                
                  |  | access_log-20140801 → access_log.1のようにする |  |  | 
                
                  |  | # vi /etc/logrotate.conf
 
 #dateext    #追加してコメントアウトする
 
 編集終了 保存
 
 
 |  | 
                
                  |  |  |  |  | 
                
                  |  |  |  | 
                
                  |  |  |  |  | 
                
                  |  |  |  |  |