LoginSignup
0
1

More than 5 years have passed since last update.

nginxをビルドした際の覚書

Last updated at Posted at 2017-01-13

試験環境

  • ubuntu 16.04
  • gcc 6.3.0

なるべく最新版で一通り揃えたい人向けかも。

ソース一式を揃える

  • zlib-1.2.10
  • openssl-1.1.0c
  • nginx-1.11.8
  • pcre-8.40
  • headers-more-nginx-module-0.32

これらを適当な場所に解凍しておく。

configure

nginxはconfigureするときにソースのライブラリの場所を指定すると自動でビルドしてくれる。
apacheのDSOみたいに*.soを読み込んでるわけじゃないので、ソースからビルドした時は静的リンクされます。
zlibとsslを有効化するときは以下のような感じ。

./configure
--with-openssl=../openssl-1.1.0c
--add-module=../headers-more-nginx-module
--with-pcre=../pcre-8.40
--with-zlib=../zlib-1.2.10
--with-http_ssl_module
--with-http_v2_module
--with-select_module
--with-poll_module
--with-pcre-jit

この設定でmake && make install。

nginx.confを編集

ヘッダを隠したいので以下の設定を追加。

server_tokens off;
more_clear_headers Server;
more_clear_headers ETag;
more_clear_headers Content-Type;
more_clear_headers Transfer-Encoding;
more_clear_headers Date;
more_clear_headers Status;
more_clear_headers X-Request-Id;
more_clear_headers X-Runtime;
more_clear_headers X-UA-Compatible;
more_clear_headers Cache-Control;
more_clear_headers Connection;
more_clear_headers Last-Modified;
more_clear_headers Cache-Control;
more_clear_headers Accept-Ranges;

起動して確認

nginx -tで設定ファイルを確認。おkだったらnginxで起動しlocalhostを確認。

お疲れ様でした。

忘れないようスクリプト書いておく

#!/bin/bash                                                                                                                                                                                                                                                            
if [ $# -ne 1 ]; then
  echo "input prefix dir without last / like:"
  echo "/home/user/local"
  echo "this must be absolute path"
  exit 1
fi

# download zlib
wget http://zlib.net/zlib-1.2.10.tar.gz
tar zxf zlib-1.2.10.tar.gz

# download openssl
wget https://www.openssl.org/source/openssl-1.1.0c.tar.gz
tar zxf openssl-1.1.0c.tar.gz

# build nginx
wget http://nginx.org/download/nginx-1.11.8.tar.gz
git clone https://github.com/agentzh/headers-more-nginx-module/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
tar zxf nginx-1.11.8.tar.gz
tar zxf pcre-8.40.tar.gz
cd nginx-1.11.8
./configure --prefix=$1  --with-openssl=../openssl-1.1.0c --add-module=../headers-more-nginx-module/ --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.10  --with-http_ssl_module --with-http_v2_module --with-select_module --with-poll_module --with-pcre-jit
make -j32
make -j32 install
cd ../ 
rm -rf nginx-1.11.8* headers-more-nginx-module* pcre-8.40* *zlib-1.2.10* openssl-1.1.0c*

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1