WEBサーバの建て方(序盤)

100000

連休は暇な人が多いのでWEBサーバの建て方を私が普段やっている手順でざっくりご紹介します。
Amazon Web Service(AWS)かGoogle Cloud Compute Platform(GCP)を使います。

このやり方でHTTPSとHTTP/2のセキュリティ万全で高速なWEBサイトを構築することができます。


SSHログインのポートを22から30000~59999の間に変更します。




sudo su -
yum update -y
vi /etc/ssh/sshd_config
# Port 22
Port 51843 # 3万から6万以下の数値に変更(覚えておくこと)
:wq で保存して終了
semanage port -a -t ssh_port_t -p tcp 51843
vi /etc/selinux/config
#SELINUX=enforcing
SELINUX=disabled

自身が無い方はdisabledにします。enforcingで有効状態だと、稀に変なエラーがでてなかなか解決できない場合があり、原因がSELINUXであることが多いです。

reboot

ここでAWSならセキュリティグループ、GCPならVPCからIPファイヤーウォールでPort22をPort51843にします。

yum install gcc pcre-devel zlib-devel gcc-c++ git wget -y
cd /usr/local/src/
useradd --shell /sbin/nologin nginx

最新バージョンを各ページでチェックします
/ /> / /> / /> / />
wget / && tar xzvf nginx-1.15.9.tar.gz
wget / && tar xzvf pcre-8.42.tar.gz
wget / && tar xzvf zlib-1.2.11.tar.gz
wget / && tar xzvf openssl-1.1.1a.tar.gz
rm -rf *.tar.gz
cd nginx*


./configure --prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/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=/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-openssl=../openssl-1.1.1a \
--with-openssl-opt=enable-ec_nistp_64_gcc_128 \
--with-openssl-opt=no-nextprotoneg \
--with-openssl-opt=no-weak-ssl-ciphers \
--with-openssl-opt=no-ssl3 \
--with-pcre=../pcre-8.42 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_secure_link_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-debug \
--with-cc-opt='-O2 -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

make
make install
nginx -t
vi /etc/systemd/system/nginx.service

:set pasteで貼り付けモードにしてiで挿入モードにしてからCtrl+Pでコピペします↓

[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on;master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on;master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on;master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target


:wqで保存して終了します


systemctl enable nginx
systemctl start nginx

yum install vim -y
cd /usr/share/vim/vim74/syntax

curl -Lkvf / -o nginx.vim

[飽きた疲れたので記事を終わります]

関連記事