「Apache」の版間の差分

提供:MoodleDocs
移動先:案内検索
編集の要約なし
22行目: 22行目:
'''キャッシング'''
'''キャッシング'''


Apache can be tuned to make pages load faster by specifying how the browser should cache the various page elements. How to do this varies slightly between OSes but there are two basic steps
Apacheでは、イメージのような各種ページ要素をローカルメモリでキャッシュして、ページがリクエストされるたびにApacheに要求しないようブラウザに指示することができます。この設定をどのようにするかOS間で若干異なりますが、以下2つの基本的なステップがあります:


# Install and enable mod_expires - refer to documentation or man pages
# mod_expiresをインストールおよび有効化してください - 詳細はドキュメントまたはmanページをご覧ください。
# Add this code to the virtual server config file within the section for the root directory (or within the .htaccess file if AllowOverrides is On):
# 次のコードをバーチャルサーバのconfigファイル内のrootディレクトリ用<directory>セクションに追加してください (または、AllowOverridesが有効の場合、.htaccessファイル):
  <IfModule mod_expires.c>
  <IfModule mod_expires.c>
   ExpiresActive On
   ExpiresActive On
   ExpiresDefault "access plus 1 seconds"
   ExpiresDefault "access plus 1 seconds"
   ExpiresByType text/html "access plus 1 seconds"
   ExpiresByType text/html "access plus 1 seconds"
   ExpiresByType image/gif "access plus 120 minutes"
   ExpiresByType image/gif "access plus 1 week"
   ExpiresByType image/jpeg "access plus 120 minutes"
   ExpiresByType image/jpeg "access plus 1 week"
   ExpiresByType image/png "access plus 120 minutes"
   ExpiresByType image/png "access plus 1 week"
   ExpiresByType text/css "access plus 60 minutes"
   ExpiresByType text/css "access plus 1 week"
   ExpiresByType text/javascript "access plus 60 minutes"
   ExpiresByType text/javascript "access plus 1 week"
   ExpiresByType application/x-javascript "access plus 60 minutes"
   ExpiresByType application/x-javascript "access plus 1 week"
   ExpiresByType text/xml "access plus 1 seconds"
   ExpiresByType text/xml "access plus 1 seconds"
  </IfModule>
  </IfModule>


The effect is to make everything stay in the cache except HTML and XML, which change dynamically. It's possible to gain a several hundred percent decrease in load times this way
この設定の効果は、動的に変わるHTMLおよびXMLを除いて、すべてをキャッシュに保持します。このようにして、ロードタイムを大幅に減らすことが可能です。どのくらいの頻度であなたのイメージが変更されるか等を考慮しながら、キャッシュタイムを調整してください。


More info: [http://www.metaskills.net/blog/heuristics/sysadmin/how-to-control-browser-caching-with-apache-2 www.metaskills.net]
詳細は次のサイトをご覧ください: [http://www.metaskills.net/blog/heuristics/sysadmin/how-to-control-browser-caching-with-apache-2 www.metaskills.net]


'''サーバ'''
'''サーバ'''

2007年11月9日 (金) 16:07時点における版

作成中です - Mitsuhiro Yoshida 2007年11月5日 (月) 09:10 (CST)

Apacheに関して言及される場合、ほとんどの人は「Apache HTTPサーバプロジェクト」のことを考えます。実際、Apacheは多くのプロジェクトを運営する「Apacheソフトウェア財団」を指し、良く知られているにもかかわらず、HTTPサーバはそのプロジェクトのひとつでしかありません。

Apache HTTPサーバでは、ウェブページをインターネット上 (またはイントラネット、単体のテストマシン上) に公開することができます。Moodelの開発に使用されているPHPスクリプト言語は、 Apache HTTPサーバに堅く統合されています。Moodleのインストールにおいて、ウェブサーバは必須の構成要素です。Apache HTTPサーバには、バージョン1およびバージョン2の異なる2つのバージョンがあります。バージョン2はバージョン1に置き換えられるべきだったのですが、アーキテクチャが大幅に異なるため、バージョン1も継続してサポートされています。両者ともPHPおよびMoodleでサポートされます。

Apache HTTPサーバプロジェクトは、以下のように説明されています:

「Apache HTTPサーバプロジェクトは、 UNIXおよびWindows NTを含む、最新オペレーティングシステムのためのオープンソースHTTPサーバを開発および保守する取り組みです。プロジェクトのゴールは、最新のHTTP標準に準拠した、安全で効率の高い拡張可能なサーバを提供することです。

1996年より、Apacheは最も人気のあるウェブサーバです。2005年11月、Netcraft Web Server Surveyの調査では、インターネット上の70%のウェブサーバがApacheを使用していることが分かりました。このように、Apacheは他の全てのウェブサーバを合わせた数より、さらに幅広く使用されています。」

Apacheのインストール

通常、ApacheはPHPおよびMySQLと共にインストールされ、この組み合わせはAMPとして知られています。詳細は、AMPのインストールをご覧ください。

Debian/Ubuntu:

apt-get install apache2

パフォーマンス

キャッシング

Apacheでは、イメージのような各種ページ要素をローカルメモリでキャッシュして、ページがリクエストされるたびにApacheに要求しないようブラウザに指示することができます。この設定をどのようにするかOS間で若干異なりますが、以下2つの基本的なステップがあります:

  1. mod_expiresをインストールおよび有効化してください - 詳細はドキュメントまたはmanページをご覧ください。
  2. 次のコードをバーチャルサーバのconfigファイル内のrootディレクトリ用<directory>セクションに追加してください (または、AllowOverridesが有効の場合、.htaccessファイル):
<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresDefault "access plus 1 seconds"
 ExpiresByType text/html "access plus 1 seconds"
 ExpiresByType image/gif "access plus 1 week"
 ExpiresByType image/jpeg "access plus 1 week"
 ExpiresByType image/png "access plus 1 week"
 ExpiresByType text/css "access plus 1 week"
 ExpiresByType text/javascript "access plus 1 week"
 ExpiresByType application/x-javascript "access plus 1 week"
 ExpiresByType text/xml "access plus 1 seconds"
</IfModule>

この設定の効果は、動的に変わるHTMLおよびXMLを除いて、すべてをキャッシュに保持します。このようにして、ロードタイムを大幅に減らすことが可能です。どのくらいの頻度であなたのイメージが変更されるか等を考慮しながら、キャッシュタイムを調整してください。

詳細は次のサイトをご覧ください: www.metaskills.net

サーバ

Apache serves webpages by spawning new child processes (smaller sub-programs) to deal with each connection. The number of these that you allow to run and to be kept in reserve has a big impact on how fast your server will run. The risk (especially on a server with a small amount of memory, such as a VPS) is that the available RAM will run out and the system will end up using the far slower hard disk as swap memory instead. To prevent this, you need to tell Apache only to have a certain number. Here is a sample set of configuration directives for a VPS server with 128MB of RAM (with up to 384 burstable), whic apparently works quite well (more info here)

Make a back up of your httpd.conf first. It’s generally found at /etc/httpd/conf/httpd.conf, then open the file with your editor e.g.

nano /etc/httpd/conf/httpd.conf

Then look for these values, which may be spread about a little and change them:

Timeout 200
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 3
MinSpareServers 5
MaxSpareServers 15
StartServers 5
MaxClients 20
MaxRequestsPerChild 2000
HostnameLookups Off

If you find that you are running out of memory (type

top

if using Linux and look at the swap figure), just lower some of the numbers. Similary, if you have extra memory, you can afford to raise them a bit. Remember to combine tuning of Apache with tuning of your database app.

SSL

If you want your website not to be hackable, you need to enable SSL so that your moodle password cannot be easily read by others as it is transmitted (as normal internet communications normally can be). There are 2 options - generate a self-signed certificate, which stops casual network sniffing, but which can ultimately be compromised with enough effort, or purchase a certificate from a vendor (about $35 per year from the cheap ones). Below are instructions for install of a self-signed certificate.

Debian and Apache2

1. generate a certification:

     apache2-ssl-certificate

for debian etch, apache2-ssl-certificate is no longer available, use make-ssl-cert instead:

         make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

2. edit /etc/apache2/ports.conf:

     Listen 80
     Listen 443

3. copy /etc/apache2/sites-available/default to /etc/apache2/sites-available/default-ssl, and change /etc/apache2/sites-available/default:

     NameVirtualHost *:80
     <VirtualHost *:80>
     ...
     </VirtualHost>

and also /etc/apache2/sites-available/default-ssl:

     NameVirtualHost *:443
     <VirtualHost *:443>
     ...
             SSLEngine on
             SSLCertificateFile /etc/apache2/ssl/apache.pem
     ...
     </VirtualHost>

4. symbolic link the ssl file:

     a2ensite default-ssl

5. don't forget to symbolic link the ssl module:

     a2enmod ssl

6. restart apache and test the connection (e.g. https://localhost/):

     /etc/init.d/apache2 restart

reference

関連情報