LoginSignup
2
3

More than 5 years have passed since last update.

nginxをソースからインストール(CentOS 7.2)

Last updated at Posted at 2018-06-22

CentOSにnginxをインストールしたので備忘録

環境

  • nginx 1.14.0
  • CentOS 7.2

インストール

何はともあれユーザー作成

# useradd -M -s /sbin/nologin nginx

ソースコードダウンロード(2018.6.22 現在のstable版)

# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.14.0.tar.gz

展開

# tar xvzf nginx-1.14.0.tar.gz 
# cd nginx-1.14.0

configure時のprefixはnginx-1.14.0にしてる(アップデート時など複数のバージョンを入れることを考慮。利用するバージョンはシンボリックリンクで切り替えて使う)

# ./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx-1.14.0 \
--with-http_ssl_module \
--with-http_stub_status_module

インストールと所有者設定

# make 
# make install
# chown -R nginx:nginx /usr/local/nginx-1.14.0

シンボリックリンク設定

# ln -snf /usr/local/nginx-1.14.0 /usr/local/nginx

ログの格納ディレクトリ作成

# mkdir /var/log/nginx
# chown nginx:nginx /var/log/nginx

nginx.confを編集(インストール時http_ssl_module組み込んだけど取り敢えず割愛)
ドキュメントルート /usr/local/www ホスト名 example.jp の場合こんな感じ

/usr/local/nginx/conf/nginx.conf
user  nginx;
worker_processes auto;
worker_rlimit_nofile 100000;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    multi_accept on;
    use epoll;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile       on;
    tcp_nopush     on;
    tcp_nodelay    on;
    keepalive_timeout 10;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;

    server_tokens off;
    gzip  off;

    server {
        listen       80;
        server_name  example.jp;
        root   /usr/local/www;
        charset utf-8;
        access_log  /var/log/nginx/access.log  main;

        location / {
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

起動

# /usr/local/nginx/sbin/nginx

確認

# curl -v http://example.jp

その他

ファイアウォールなどで80番Port閉じてる場合はちゃんと開ける

2
3
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
2
3