步驟一:手動安裝nginx環境,並記錄全過程:
#使用yum更新系統
yum -y update
#下面編譯安裝tengine,查看有哪些包需要安裝
#安裝wget包,用於獲取安裝軟件包
yum -y install wget
cd /usr/local/src
#下載nginx安裝包,並指定放置目錄/usr/local/src
wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz -P /usr/local/src/
#z匹配.gz x解壓 f本地
tar -zxf tengine-2.1.2.tar.gz
#創建nginx需要的用戶和組
groupadd -r nginx
useradd -g nginx -M nginx
#tengine初次編譯
./configure --prefix=/usr/local/tengine \
--user=nginx --group=nginx
#報錯以及補充系統包:
yum -y install gcc pcre-devel openssl-devel
#初次編譯通過,增加nginx模塊配置再次編譯:
--with-http_realip_module #nginx獲取客戶端真實IP的模塊
--with-http_sub_module #用於替換網站頁面關鍵字--平常基本沒啥用
--with-http_gzip_static_module #靜態緩存壓縮,用於減少流量
--with-http_gunzip_module #為不支持gzip模塊的客戶端提供解壓縮服務,用於節省空間減少IO
--with-http_ssl_module #使nginx支持https
--with-pcre #nginx支持pcre正則,主要是支持rewrite功能
--with-http_stub_status_module #用於監控nginx狀態
完整編譯命令如下:
./configure --prefix=/usr/local/tengine \ --user=nginx --group=nginx \ --with-http_realip_module \ --with-http_gzip_static_module \ --with-http_gunzip_module \ --with-pcre \ --with-http_stub_status_module \ --with-http_ssl_module
#編譯安裝
make & make install
#啟動nginx
/usr/local/tengine/sbin/nginx
步驟二:根據以上步驟構建dockerfile生成nginx鏡像
Dockerfile
################################################### #Dockerfile to build mysqlDB container images #base on centos ################################################### #Set the base image to Centos6 FROM centos:6 #File Suthor MAINTAINER liujian@wanbu.com.cn #install basic rpm RUN yum -y update RUN yum -y install wget gcc pcre-devel openssl-devel RUN wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz -P /usr/local/src/ \ && groupadd -r nginx && useradd -g nginx -M nginx RUN cd /usr/local/src/ \ && tar -zxf tengine-2.1.2.tar.gz \ && cd tengine-2.1.2/ \ && ./configure --prefix=/usr/local/tengine --user=nginx --group=nginx --with-http_realip_module --with-http_gzip_static_module --with-http_gunzip_module --with-pcre --with-http_stub_status_module --with-http_ssl_module \ && make && make install \ && ln -s /usr/local/tengine/sbin/nginx /usr/sbin/nginx \ && yum -y remove wget gcc pcre-devel openssl-devel ADD nginx.conf /usr/local/tengine/conf/ EXPOSE 80 CMD ["nginx","-g","deamon off;"]
#制定Dokcerfile構建nginx鏡像
docker build -t nginx_test:v1.0 .
#使用鏡像創建容器,測試nginx運行情況
docker run -itd -p 0.0.0.0:7788:80 --name nginx_image_test nginx_test:v1.0
#訪問正常,但是nginx配置文件無法修改,只能啟動運行。
如果在測試環境需要修改配置文件重啟等,可以使用:
#將dockerfile內部CMD ["nginx","-g","deamon off;"]替換為
ENTRYPOINT /usr/sbin/nginx -c /etc/nginx/nginx.conf && /bin/bash
