利用 Docker 快速建立 nginx 基礎示範

使用 nginx image 建立名稱為 nginx 的 docker 容器 ,在背景執行,將 80 port 映射到本機的 80 port
    
docker run --name nginx -p 80:80 -d nginx
    

進入容器:
    
docker exec -it nginx bash
    

主要設定檔位置:
    
/etc/nginx/nginx.conf
    

主要設定檔內容:
    
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
    

預設 index.html 位置:
    
/usr/share/nginx/html/index.html
    

檢查 nginx 設定檔是否正確:
    
sudo nginx -t
    

nginx 熱重載設定檔:
    
nginx -s reload
    



參考資料:
docker image - nginx
nginx.odcs - Beginner’s Guide

留言