nginxの基本設定
cd /etc/nginx/
cp -p nginx.conf nginx.conf.org
vi nginx.conf
#worker_processes 1; <– サーバーのCPU数と同じに変更する。変更したらworker_cpu_affinityにてCPUとnginxのプロセスを割り当て設定をする。4コアなら以下の通り。2コアなら(0101 1010;) worker_processes 4; worker_cpu_affinity 0001 0010 0100 1000;
#access_log /var/log/nginx/access.log main; <–ログの名称を変更する。エラーログを追加する。 access_log /var/log/nginx/mlimg.hogehoge.jp-access.log main;
cd /etc/nginx/conf.d
cp -p default.conf server-A.conf
vi server-A.conf
server_name mlimg.hogehoge.jp;
access_log /var/log/nginx/server-A.com-access.log main;
error_log /var/log/nginx/server-A.com-error.log warn;
service nginx configtest
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
ps aux | grep nginx | grep -v grep
root 1584 0.0 0.0 45140 1164 ? Ss 17:11 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 1585 0.0 0.0 45564 2024 ? S 17:11 0:00 nginx: worker process nginx 1586 0.0 0.0 45564 2068 ? S 17:11 0:00 nginx: worker process nginx 1587 0.0 0.0 45564 1828 ? S 17:11 0:00 nginx: worker process nginx 1589 0.0 0.0 45564 1812 ? S 17:11 0:00 nginx: worker process
nginxの構文チェック
nginxをSSLアクセラレータとして運用する
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
ssl on;
ssl_certificate /etc/nginx/ssl/hogehoge.crt;
ssl_certificate_key /etc/nginx/ssl/hogehoge.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://backend;
}
location = /favicon.ico {
access_log off; log_not_found off;
}
}
nginxをロードバランサーとして活用する
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
proxy_pass http://backend1;
}
service nginx configtest
servcie nginx reload
バックエンドのサーバーのapacheのログ設定 [#zaa6baa4]