- 追加された行はこの色です。
- 削除された行はこの色です。
*nginx(Ubuntu) [#u044f966]
nginxはオープンソースのWebサーバーである。~
ロードバランサなどの機能を備える。~
*ダウンロード [#q07fa175]
Linux用のアーカイブを[[GlassFish Server Open Source Edition 4.0 Download>https://glassfish.java.net/download.html]]からダウンロードする。~
右側のa specific installerからLocalisationに「Multilingual」を選択し、glassfish-4.0-ml.zip をダウンロードする。~
*インストール [#f5ce1b49]
Ctrl+Alt+Tで端末を起動する。~
ここからはコマンドラインで操作を行う。~
~
下記のコマンドを実行する。パスワードを聞かれるので入力する。~
途中で確認メッセージが表示されるので、yを入力する。~
>
sudo apt-get install nginx
~
下記の設定ファイルを編集しnginxを再起動する。~
ここでは既存の2台のサーバーのロードバランサを設定する。~
>
sudo gedit /etc/nginx/nginx.conf
sudo gedit /etc/nginx/sites-available/default
sudo /etc/init.d/nginx restart
/etc/nginx/nginx.confの設定を行う。~
http内にupstream 名称 {}を作成し、サーバーの数だけserver サーバー名:ポートオプション;の形で記入する。~
アクセスのたびに接続先のサーバーが変わってしまうとセッションが維持できないないため、接続先をcokkieの値に保存するsticky cookieの機能があるが、sticky cookieの機能は無料では利用できないためここでは設定しない。~
なお、IPのハッシュ値を元にサーバーを選択するip_hashは無料で利用できる。~
>
http {
##
# Basic Settings
##
upstream web {
#AP1
server AP1.local:28080 weight=1 max_fails=1 fail_timeout=10;
#AP2
server AP2.local:28080 weight=1 max_fails=1 fail_timeout=10;
#sticky cookie;
}
(以下変更なしのため省略)
/etc/nginx/sites-available/defaultの設定を行う。~
location内のtry_files $uri $uri/ =404;を#でコメントにし、proxy_pass http://upstreamの名称;を入力する。~
>
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
proxy_pass http://web;
}
(以下変更なしのため省略)
nginxの起動と終了は下記のコマンドで行う。PCの起動時には自動的に起動される。~
>
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
~
nginxのログは下記に記録される。~
>
cat /var/log/nginx/error.log
*コメント [#m88379f7]
#comment