サーバー設定 · 1 min read · Feb 08, 2026
RHEL 5.2でNginxを使用してApacheの負荷を軽減する
RHEL 5.2でNginxを使用してApacheの負荷を軽減する
このハウツーでは、RHEL 5.2に基づくApacheサーバーを加速するためにNginxをインストールおよび構成する方法を説明します。
1. インストールされているパッケージを更新する
yum install update2. 新しいパッケージをインストールする
yum install -y httpd-develwget http://rpmfind.net/linux/EPEL/5Server/i386/nginx-0.6.31-3.el5.i386.rpmrpm nginx-0.6.31-3.el5.i386.rpm3. /etc/nginx/nginx.confを編集する
Nginxをリバースプロキシとして設定します:
nano /etc/nginx/nginx.confworker_processes 1; を worker_processes 2; に変更します;
次の内容を置き換えます
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# /etc/nginx/conf.d ディレクトリから設定ファイルを読み込む
include /etc/nginx/conf.d/*.conf;
#
# デフォルトサーバー
#
server {
listen 80;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}を
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
# /etc/nginx/conf.d ディレクトリから設定ファイルを読み込む
include /etc/nginx/conf.d/*.conf;
#
# デフォルトサーバー
#
server {
listen 80;
server_name YOURSERVERNAME;
#charset koi8-r;
#access_log logs/host.access.log main;
#メインロケーション
location / {
proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
root /usr/share/nginx/html;
index index.html index.htm index.php;
}この機能により、Nginxはこれらのファイルタイプで動作します:
次の内容を変更します
#location ~ \.ht {
#deny all;を
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js)$ {root /var/www;}4. nginx.confを確認する
nginx -t結果は次のようになります:
2008/07/17 16:09:46 [info] 17197#0: 設定ファイル /etc/nginx/nginx.conf の構文は正しいです
2008/07/17 16:09:46 [info] 17197#0: 設定ファイル /etc/nginx/nginx.conf は正常にテストされました
5. rpaf-2.0モジュールのインストール
このモジュールは、ApacheにアクティブなNginx IPを提供します。
cd /usr/local/srcwget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gztar xzf mod_rpaf-0.6.tar.gzcd mod_rpaf-0.6rpafモジュールのコンパイル:
nano /usr/local/src/mod_rpaf-0.6/makefileAPXS=$(shell which apxs) を APXS=/usr/sbin/apxs に変更します。
コンパイル方法:
I)
make rpaf-2.0 && make install-2.0II)
apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c6. httpd.confを編集する
nano /etc/httpd/conf/httpd.conf次の内容を追加します
...
LoadModule rpaf_module modules/mod_rpaf-2.0.so
....
#Mod_rpafの設定
RPAFenable On
RPAFproxy_ips 127.0.0.1 REALIP1 REALIP2
RPAFsethostname OnListen 80 を Listen 8080 に変更します。Nginxはポート80を使用します。
7. Apacheを再起動し、Nginxを起動する
service httpd restartservice nginx start8. 結果を表示する
NginxによるApacheテストページ:

新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。