基本的に「次回は~をやる予定」を守った試しが無いです。仕方ないんです。だってやりたいことや書きたい事って変わってしまうから。
そんなわけで、今日は唐突にnginxをCentOS7にインストールします。
id=”目次”>目次
nginxのインストール
とりあえずnginxをインストールしようとしてみます。
2017/05/11現在の最新版は1.12.0なのでこちらを入れます。
# wget https://nginx.org/download/nginx-1.12.0.tar.gz # tar xvfz nginx-1.12.0.tar.gz # cd nginx-1.12.0/ # ./configure --prefix=/usr/local/nginx ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
pcre-develが無いと思うので入れます。ちなみにpcreってperl互換の正規表現を扱うためのライブラリだったんですね。初めて知りました。
# yum install pcre-devel # ./configure --prefix=/usr/local/nginx ./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option.
zlib-develも入れます。
# yum install zlib-devel # ./configure --prefix=/usr/local/nginx Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
ではmakeとmake installをば…
# make # make install
これでインストールまでは完了です。続いて、起動させます。
nginxの設定
とりあえずnginx用のユーザーを作っておきます。
#useradd nginx
nginxのconfig周りの知識皆無なので手探りでやって行きます。
# cd /usr/local/nginx/ # ls conf html logs sbin # cd conf/
なんかconfの下に色々ありますが、きっとnginx.confをいじれば起動するでしょう(適当)
user nginx; worker_processes 1; error_log logs/error.log; error_log logs/error.log notice; error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; access_log logs/access.log; sendfile on; keepalive_timeout 65; server { listen 80; server_name test1.example.com; access_log logs/host.access.log; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
とりあえず最低限起動させるだけなのでこんな感じで。。
最後にnginx.serviceを作っておく。
# cat /etc/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID [Install] WantedBy=multi-user.target
これでstart/stopで動けばオッケー。
# systemctl start nginx # ps aux |grep nginx root 17395 0.0 0.0 20484 616 ? Ss 12:50 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nginx 17396 0.0 0.0 23012 1372 ? S 12:50 0:00 nginx: worker process root 17398 0.0 0.0 9032 660 pts/0 S+ 12:50 0:00 grep --color=auto nginx # systemctl restart nginx # ps aux |grep nginx root 17412 0.0 0.0 20484 612 ? Ss 12:50 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf nginx 17413 0.0 0.0 23012 1368 ? S 12:50 0:00 nginx: worker process root 17415 0.0 0.0 9032 660 pts/0 S+ 12:50 0:00 grep --color=auto nginx # systemctl stop nginx # ps aux |grep nginx root 17426 0.0 0.0 9032 656 pts/0 S+ 12:50 0:00 grep --color=auto nginx
細かい設定は流れでやっていきます。とりあえず今回はこれで終了。