CentOS7にyumでnginx1.11をインストール

CentOS7にyumでnginxの最新版をインストールする。

nginxインストール

nginx最新版を入れるため、本家サイトに従いnginxのリポジトリを追加する。

sudo vim /etc/yum.repos.d/nginx.repo

以下を記述。enabledを1にすることで、このリポジトリが常時有効になる。

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

nginxインストール。

sudo yum install nginx

バージョン確認。「nginx version: nginx/1.11.1」と表示された。

nginx -v

デフォルトで組み込まれたモジュールを確認する。

nginx -V

# 以下が表示
nginx version: nginx/1.11.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --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-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=njs-1c50334fbea6/nginx --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --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'

HTTP2で常時SSL化したいので、以下2つ入っていればOKかな。
–with-http_v2_module
–with-http_ssl_module

nginx起動。

sudo systemctl start nginx

サービスとして起動。

sudo systemctl enable nginx

CentOS7のfirewalld

firewalldを有効にする。

sudo systemctl enable firewalld
 sudo systemctl start firewalld

httpサービスを公開する。

sudo firewall-cmd --permanent --zone=public --add-service=http

firewalldをリロードし、設定を反映。

sudo firewall-cmd --reload

起動しているサービスの確認。

sudo firewall-cmd --list-services --zone=public  --permanent

「dhcpv6-client http ssh」と表示される。

この時点でIP直接指定したらnginxのwelcomeページが表示される。

2022 XXX Directory: Sex, Porn & XXX Cam Sites Listing
XXX.xxx is the world's leading free porn directory. Choose from thousands of hardcore sex sites with streaming video, high quality photos and live sex cam.

githubに設定ファイルを保存

nginxの設定ファイルはこれから度々修正します。
git管理して変更履歴を追えるようにしとく。

githubでリモートリポジトリを先に作成しておきます。

nginxの設定ファイルがあるディレクトリへ移動。

cd /etc/nginx

ローカルリポジトリを作成。

git init
git add .
git commit -u "first commit"

リモートへ反映。

sudo git remote add origin https://github.com/runble1/nginx.conf.git
sudo git push -u origin master

nginx使い方方針

リバースプロキシ

ユーザのリクエストを受け取り、上位サーバ(アップストリームサーバ)に転送する機能。

主に2つの役割

1.フロントサーバにおけるリバースプロキシ
・ロードバランス(複数のサーバにリクエストを振り分ける)
・コンテンツキャッシュ(ユーザと直接コネクションを持つサーバで行うほうが効率がいい)
・HTTPS通信の終端化

→それぞれのサーバで共通した処理を一括して行うことで、アプリケーションの負荷を減らす

2.Webアプリケーションサーバにおけるリバースプロキシ
・静的ファイルの配信
・リクエストの書き換え
・アクセス制限、不正なリクエストのフィルタリング
・gzip圧縮転送
・リクエストのロギング
・リクエストとレスポンスのバッファリング

参考

CentOS7 + php7 + nginx + php-fpm環境にwordpressインストール

コメント

タイトルとURLをコピーしました