Nginxをカジュアルに一般ユーザで起動してみる
カジュアルにNginxをアプリケーションサーバのフロントに置いて動かしたい!ということがあったのでそのためにやったことのメモ。
nginxコマンドのオプション
nginx -h
nginx version: nginx/1.8.0 Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/Cellar/nginx-full/1.8.0_2/) -c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf) -g directives : set global directives out of configuration file
なので、-sと-pと-cあたりを使います。
conf
nginx.confはこんな感じ。
8888ポートで待ち受けて、localhost:10001とlocalhost:10002に振り分けます。
worker_processes 1;
error_log logs/error.log warn;
pid nginx.pid;
events {
worker_connections 1024;
}
http {
upstream app {
server localhost:10001;
server localhost:10002;
}
default_type application/json;
server {
listen 8888;
server_name localhost;
location / {
proxy_pass http://app;
}
}
}
起動
nginx -p $(pwd) -c nginx.conf
終了
nginx -p $(pwd) -c nginx.conf -s stop
実にカジュアル。