狂ったお茶会のlog

後で起きる自分のためのメモ

nginxのソースをサーバにインストールする

nginxをソースコードからのビルドしたので雑なメモ

CentOS

サーバに入ったらrootになる

sudo su -

移動

cd /usr/local/src

http://nginx.org/en/download.html
の、Stable versionをDL
今回は1.8.0

curl -O http://nginx.org/download/nginx-1.8.0.tar.gz

以下でもできるようだがwgetが入ってなかったぽいのでcurlでやった、一応メモ

wget http://nginx.org/download/nginx-1.8.0.tar.gz

DLしたのを展開

tar xvzf nginx-1.8.0.tar.gz

展開するとディレクトリができるので移動

cd nginx-1.8.0/

そしてconfigureしたい

./configure

けどエラー

checking for OS
 + Linux 2.6.32-431.29.2.el6.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

コンパイラが無いらしいのでinstall

yum install gcc

installしたので再度configure

./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.

また何か無い
以下install

yum -y install pcre-devel

※メモ:オプション -y は 問い合わせにすべて「y」と返答するオプション

再度configure

./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.

まだ何か無い のでinstall

yum -y install zlib-devel

で今度こそconfigure
ビャーっと出力されて最後こう出た
makefile出来たっぽい

creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  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

ビャーッとコンパイル&インストールされる

起動ファイルとか作ると便利っぽいけど、一旦とりあえず起動

 /usr/local/nginx/sbin/nginx

特になんか表示してくれたりはしないので以下で確認してみる

ps aux | grep nginx

そうすると以下みたいにプロセスが表示されてれば動いてるっぽい

root     27808  0.0  0.0  20328   624 ?        Ss   10:31   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   27809  0.0  0.1  20756  1216 ?        S    10:31   0:00 nginx: worker process      
root     27816  0.0  0.0 103248   872 pts/0    S+   10:31   0:00 grep nginx

停止してみる

/usr/local/nginx/sbin/nginx -s quit

ps aux | grep nginxで確認すると以下みたいにnginxのプロセスは消えてるので停止してるっぽい

root     27831  0.0  0.0 103248   876 pts/0    S+   10:31   0:00 grep nginx

nginx動いてる状態でブラウザでIPにアクセスするとこういうのが出る f:id:dormouse666:20150923232108p:plain

/usr/local/nginx/logs/access.logを見るとアクセスが来てるのがわかる

参考

ここらへんを見ました

Linux入門 - nginxの設定と使い方 - Webkaru

Nginxインストールメモ - Qiita

これから始める人のためのNginx(2):Nginxのインストールと基本設定 (1/4) - @IT

linux/nginx - おどうぐ箱

簡単!5分でnginx1.05をCentOS5.6にインストールする方法(ソースコードをコンパイル) · DQNEO起業日記

Curlコマンドの使い方例。curlコマンドの情報は意外と少ない・・・ - それマグで!