LoginSignup
0
0

More than 5 years have passed since last update.

猫オリジナルのNginx環境の構築編(TLSv1.3対応)

Last updated at Posted at 2018-12-11

はじめに

OneNoteぶっ飛んだおかげで、いろんな設定を行うノートをQiitaに避難中ですが、そのノート第二弾に書き直します(TLSv1.3も対応してるので)

Nginxは普通にyumで一度入れときます

systemd のコマンドとか作るの面倒なので。そういうの無い人は...
あと、入れたあとに enabled=0 にしておく必要があります(更新されたら意味が無い)

コンパイラーを準備する

Centos7のコンパイラは古いので、別途新しいコンパイラを入れてます。なんとなく、新しい方が、良くないですか?たぶん...。

drizzle は、NginxにMySQLを直接触れる環境を入れる場合のみ必要です

init.sh
#!/bin/bash

# コンパイル、ビルド環境インストール
yum -y install centos-release-scl
yum -y install wget tar yum-utils
yum -y install epel-release pcre-devel libxslt-devel perl-ExtUtils-Embed gd-devel
yum -y install GeoIP-devel
yum-config-manager --enable rhel-server-rhscl-7-rpms
yum -y install devtoolset-7

# remi
wget http://rpms.famillecollet.com/enterprise/remi.repo > /etc/yum.repos.d/remi.repo

# Nginx+MySQL用
cd /usr/local/src
wget http://agentzh.org/misc/nginx/drizzle7-2011.07.21.tar.gz
tar xzvf drizzle7-2011.07.21.tar.gz
cd drizzle7-2011.07.21/
./configure --libdir=/usr/local/lib64 --without-server
make libdrizzle-1.0
make install-libdrizzle-1.0
cd /usr/local/src
rm -rf drizzle*

コンパイル

自動でバージョンチェックしにいったり、インストール済みバージョン確認してその項目飛ばしたり出来ればいいのですけどね、猫にその技術は無いので、バージョンは毎回チェックしに行って記述してますよ。あと、エラーチェックもないので、失敗するとコケてる。
Bashも、もうちょっと得意になれば、自動でチェックして必要なときに再コンパイルというのができるのですが、いやはや、Perlとかでやった方がいい?

あと、不要なオプションものは、自力で消す!

nginx_compile.sh
#!/bin/bash

### === version setting =======
## https://www.openssl.org/
sslver=1.1.1a

## https://nginx.org/en/download.html
nginxver=1.15.8

## https://www.zlib.net/
zlibver=1.2.11

## slowfs, purge (cache module) version
## http://labs.frickle.com/files/
slowfs=1.9
purge=2.3

## develkit version(misc,lua include module)
## https://github.com/simplresty/ngx_devel_kit/releases
develkit=0.3.0

## misc version 
## https://github.com/openresty/set-misc-nginx-module/tags 
misc=0.32

## lua jit app version
## http://luajit.org/download.html
luajit=2.0.5

## lua nginx module version
## https://github.com/openresty/lua-nginx-module/tags
lua=0.10.13

## nginx mysql module version
## https://github.com/openresty/drizzle-nginx-module/tags
drizzle=0.1.11

## nginx json module version
## https://github.com/openresty/rds-json-nginx-module/tags
json=0.15


## ===== source code get ======
# openssl get
cd /usr/local/src
wget https://www.openssl.org/source/openssl-$sslver.tar.gz
tar -zxf openssl-$sslver.tar.gz
rm -f ./openssl-$sslver.tar.gz

# zlib get
cd /usr/local/src
wget https://zlib.net/zlib-$zlibver.tar.gz
tar -zxf zlib-$zlibver.tar.gz
rm -f ./zlib-$zlibver.tar.gz

# nginx
cd /usr/local/src
wget https://nginx.org/download/nginx-$nginxver.tar.gz
tar -zxf nginx-$nginxver.tar.gz
rm -f ./nginx-$nginxver.tar.gz

# slowfs
cd /usr/local/src
wget http://labs.frickle.com/files/ngx_slowfs_cache-$slowfs.tar.gz
tar -zxf ngx_slowfs_cache-$slowfs.tar.gz
rm -f ./ngx_slowfs_cache-$slowfs.tar.gz

# ngx_cache_purge
cd /usr/local/src
wget http://labs.frickle.com/files/ngx_cache_purge-$purge.tar.gz
tar -zxf ngx_cache_purge-$purge.tar.gz
rm -f ./ngx_cache_purge-$purge.tar.gz

# ngx_devel_kit
cd /usr/local/src
wget https://github.com/simplresty/ngx_devel_kit/archive/v$develkit.tar.gz
tar -zxf v$develkit.tar.gz
rm -f ./v$develkit.tar.gz

# misc-nginx-module
cd /usr/local/src
wget https://github.com/openresty/set-misc-nginx-module/archive/v$misc.tar.gz
tar -zxf v$misc.tar.gz
rm -f ./v$misc.tar.gz

# luajit
cd /usr/local/src
wget http://luajit.org/download/LuaJIT-$luajit.tar.gz
tar -zxf LuaJIT-$luajit.tar.gz
rm -f ./LuaJIT-$luajit.tar.gz

# lua
cd /usr/local/src
wget https://github.com/openresty/lua-nginx-module/archive/v$lua.tar.gz
tar -zxf v$lua.tar.gz
rm -f ./v$lua.tar.gz

# drizzle
cd /usr/local/src
wget https://github.com/openresty/drizzle-nginx-module/archive/v$drizzle.tar.gz
tar -zxf v$drizzle.tar.gz
rm -f ./v$drizzle.tar.gz

# json
cd /usr/local/src
wget https://github.com/openresty/rds-json-nginx-module/archive/v$json.tar.gz
tar -zxf v$json.tar.gz
rm -f ./v$json.tar.gz


### ==== compile & build run ====
# luajit compile
cd /usr/local/src
cd LuaJIT-$luajit
make PREFIX=/usr/local/bin CC="gcc -m64"
make install

# openssl build
cd /usr/local/src
cd openssl-$sslver
./config shared zlib
make && make install
echo "/usr/local/lib64/" > /etc/ld.so.conf.d/lib64.conf
ldconfig

# zlib build
cd /usr/local/src
cd zlib-$zlibver
./configure --prefix=/opt/zlib/zlib-$zlibver
make && make install

# nginx build
cd /usr/local/src/nginx-$nginxver

./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_perl_module=dynamic \
--with-pcre-jit \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-zlib=/usr/local/src/zlib-$zlibver \
--with-openssl=/usr/local/src/openssl-$sslver \
--with-openssl-opt=enable-tls1_3 \
--add-module=/usr/local/src/ngx_cache_purge-$purge \
--add-module=/usr/local/src/ngx_slowfs_cache-$slowfs \
--add-module=/usr/local/src/ngx_devel_kit-$develkit \
--add-module=/usr/local/src/set-misc-nginx-module-$misc \
--add-module=/usr/local/src/drizzle-nginx-module-$drizzle \
--add-module=/usr/local/src/rds-json-nginx-module-$json \
--add-module=/usr/local/src/lua-nginx-module-$lua \
--with-cc-opt='-O3 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' \
 --with-ld-opt="-Wl,-E,-rpath,/usr/local/lib"

make
make install

systemctl restart nginx
systemctl status nginx

cd /usr/local/src
rm -rf ./openssl-*
rm -rf ./nginx-*
rm -rf ./zlib-*
rm -rf ./ngx_*
rm -rf ./*nginx-module-*
rm -rf ./LuaJIT*

Nginxに設定

TLSv1.0, TLSv1.1も対象から外すことが推奨になってるので外してます。古いブラウザやOS使ってるとアウトになる場合もあるので吟味が必要です。
以下の設定で、ssl server test はクリアしていました。

## SSL通信方式
ssl_protocols TLSv1.2 TLSv1.3;

## 共通鍵暗号方式
ssl_prefer_server_ciphers on;
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA512:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:ECDH+AESGCM:ECDH+AES256:DH+AESGCM:DH+AES256:!aNULL:!eNULL:!LOW:!RC4:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS;

Lua とかは練習中

新しい言語増えるたびにへこたれてます。もう、キビシイです...

0
0
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
0