#author("2019-01-08T09:37:29+00:00","","")
#author("2019-01-11T03:46:31+00:00","","")
* Nginx [#d945706b]
#setlinebreak(on)

#contents
-- 関連
--- [[dockerでサクッとNginx環境構築]]
--- [[Nginx+uwsgiでFlaskアプリケーション]]
-- 参考
--- 公式サイト : https://nginx.org/en/
--- インストール: http://nginx.org/en/docs/install.html


** dockerコンテナとして起動する(お試し) [#xa7b3f80]
#html(<div style="padding-left:10px;">)
#myterm2(){{
docker pull nginx:latest
sudo docker run -d -p 8080:80 nginx
}}

あとは docker exec -it でコンテナに入ってファイル作成等を行う。

- デフォルトでは /usr/share/nginx/html がドキュメントルート
- nginx のコンテナイメージは debianベース(コンテナに必要なコマンド等がない場合は apt-get  update && apt-get install xxx で都度インストール)

#html(</div>)

** dockerイメージを作る [#x1912d55]
#html(<div style="padding-left:10px;">)

*** 配信するコンテンツの作成 [#z6cd76e3]
#html(<div style="padding-left:10px;">)

www/index.html
#mycode2(){{
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
</head>
<body>

Test Nginx!

</body>
</html>
}}
#html(</div>)

*** Dockerfileの作成 [#q26a6404]
#html(<div style="padding-left:10px;">)

Dockerfile
#mycode2(){{
FROM nginx

RUN mkdir -p /var/www
COPY www /var/www
COPY default.conf /etc/nginx/conf.d/default.conf

CMD nginx -g "daemon off;"
}}
#html(</div>)

*** コンテナのビルド [#yde6c0c2]
#html(<div style="padding-left:10px;">)
#myterm2(){{
docker build ./ -t nginx-sample1
}}
#html(</div>)

*** コンテナの起動 [#s636d0af]
#html(<div style="padding-left:10px;">)
#myterm2(){{
docker run -d -p 8080:80 nginx-sample1
}}
#html(</div>)

#html(</div>)


** CentOS へのインストール [#d154a64f]
#html(<div style="padding-left:10px;">)

http://nginx.org/en/linux_packages.html#stable

*** yum リポジトリの追加 [#pc0a7507]
#html(<div style="padding-left:10px;">)

/etc/yum.repos.d/nginx.repo
#mycode2(){{
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
}}

#html(</div>)

*** インストール [#aeb23b7a]
#html(<div style="padding-left:10px;">)
#myterm2(){{
yum install -y nginx
}}
#html(</div>)


*** 起動 [#j0468479]
#html(<div style="padding-left:10px;">)
#myterm2(){{
# 自動起動をON
sudo systemctl enable nginx

# 起動
sudo systemctl start nginx
}}
#html(</div>)


#html(</div>)


** 設定ファイルについて [#vcd195ba]
#html(<div style="padding-left:10px;">)

メインの設定ファイルである /etc/nginx/nginx.conf では  /etc/nginx/conf.d 配下にあるバーチャルホスト毎の設定ファイルを読み込むように記述されている。
※Apacheと同じ

/etc/nginx/nginx.conf
#mycode2(){{
.
.
http {
    .
    .
    include /etc/nginx/conf.d/*.conf;
}
}}

インストール直後の /etc/nginx/conf.d 配下には、default.conf というデフォルトの設定ファイルのみが存在する。
※パっと見はだいたいApacheと似たカンジ。

/etc/nginx/conf.d/default.conf
#mycode2(){{
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
}}

#html(</div>)

** SSLサーバ証明書の設定 [#p9dc86d3]
#html(<div style="padding-left:10px;">)
#TODO
#html(</div>)


トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS