Nginxは静的コンテンツの高速配信ができるサーバ。
同時リクエストの処理用に特化されている。また、余計な機能が付いていない為、必要なメモリ等は少ない。
Apacheのように各プログラム言語用のモジュールを持たない為、動的コンテンツの配信はリバースプロキシの機能を利用して、FastCGI, uWSGI, Passenger 等の各種コンテナに処理を振り分けるようにして使用される。
docker pull nginx:latest sudo docker run -d -p 8080:80 nginx
あとは docker exec -it でコンテナに入ってファイル作成等を行う。
www/index.html
<!doctype html> <html lang="ja"> <head> <meta charset="utf-8"> </head> <body> Test Nginx! </body> </html>
Dockerfile
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;"
docker build ./ -t nginx-sample1
docker run -d -p 8080:80 nginx-sample1
http://nginx.org/en/linux_packages.html#stable
/etc/yum.repos.d/nginx.repo
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
yum install -y nginx
# 自動起動をON sudo systemctl enable nginx # 起動 sudo systemctl start nginx
メインの設定ファイルである /etc/nginx/nginx.conf では /etc/nginx/conf.d 配下にあるバーチャルホスト毎の設定ファイルを読み込むように記述されている。
※Apacheと同じ
/etc/nginx/nginx.conf
.
.
http {
.
.
include /etc/nginx/conf.d/*.conf;
}
インストール直後の /etc/nginx/conf.d 配下には、default.conf というデフォルトの設定ファイルのみが存在する。
※パっと見はだいたいApacheと似たカンジ。
/etc/nginx/conf.d/default.conf
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;
#}
}