站長資訊網
最全最豐富的資訊網站

線上Nginx鏡像構建及容器使用

1.Dockerfile-nginx文件內容:

FROM CentOS:latest

MAINTAINER nan
RUN yum -y install gcc gcc-c++ make
openssl-devel pcre-devel gd-devel
libxml2-devel libxslt-devel zlib-devel
gd-devel perl-ExtUtils-Embed
iproute net-tools telnet wget curl &&
yum clean all &&
useradd -s /sbin/nologin -M nginx &&
mkdir -p /var/tmp/nginx &&
rm -rf /var/cache/yum/
RUN wget http://nginx.org/download/nginx-1.15.9.tar.gz &&
tar -zxvf nginx-1.15.9.tar.gz &&
cd nginx-1.15.9 &&
./configure –prefix=/usr/local/nginx –sbin-path=/usr/local/nginx/sbin/nginx
–conf-path=/usr/local/nginx/conf/nginx.conf –error-log-path=/var/log/nginx/error.log
–http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx/nginx.pid
–user=nginx –group=nginx –with-http_ssl_module –with-http_stub_status_module
–with-threads –with-file-aio –with-http_v2_module
–with-http_realip_module –with-http_addition_module
–with-http_xslt_module –with-http_image_filter_module
–with-http_sub_module –with-http_flv_module
–with-http_mp4_module –with-http_gunzip_module
–with-http_gzip_static_module –with-http_auth_request_module
–with-http_secure_link_module –with-http_slice_module
–with-http_perl_module –with-compat
–with-stream –with-stream_ssl_module –with-stream_realip_module
–with-http_gzip_static_module –http-client-body-temp-path=/var/tmp/nginx/client
–http-proxy-temp-path=/var/tmp/nginx/proxy –http-fastcgi-temp-path=/var/tmp/nginx/fcgi
–http-uwsgi-temp-path=/var/tmp/nginx/uwsgi –http-scgi-temp-path=/var/tmp/nginx/scgi –with-pcre &&
make -j 4 && make install &&
cd / && rm -rf nginx-1.15.9 &&
ls -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/nginx/sbin
WORKDIR /usr/local/nginx
EXPOSE 80
CMD [“nginx”, “-g”,”daemon off;”]

2.構建鏡像命令:

docker build -t nginx:v2 -f Dockerfile-nginx .

-t:代表 tag -f:指定dockerfile文件 .用當前目錄的環境變量

3.從本地鏡像倉庫下載nginx鏡像

docker pull xx.xx.xx.xx/library/nginx:v2

4,在要安裝nginx的服務器創建目錄

4.1 配置文件目錄:mkdir -p /opt/nginx/conf/vhost

/opt/nginx/conf下有兩個:一個為nginx.conf,設置nginx標準配置(隨著業務可能需優化);標準配置文件詳見nginx.conf
參考:

server_tokens off;
user nginx;
worker_processes 4;
worker_rlimit_nofile 65535;
error_log /var/log/nginx/error.log;
events
{
use epoll;
worker_connections 10240;

}
http{
log_format  main  ‘$remote_addr $remote_user [$time_local] “$request” ‘
              ‘$status $body_bytes_sent “$http_referer” ‘
              ‘$http_user_agent $http_x_forwarded_for $request_time $upstream_response_time $upstream_addr $upstream_status’;
access_log  /var/log/nginx/access.log  main;               
include      mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;       
sendfile on;
tcp_nopush    on;     
keepalive_timeout 60;
send_timeout 15;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

gzip on;
gzip_min_length 1k;
gzip_buffers    4 32k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types      text/plain application/x-Javascript text/css application/xml;
gzip_vary on;
include /usr/local/nginx/conf/vhost/*.conf;

}

> 另一個為vhost,vhost配置不同的域名解析文件(就是真正的業務配置)
>  vhost下的文件統一命名格式:域名.conf
參考:

upstream gw_ma {
server xx.xx.xx.xx:5601;

}

server {

listen 80;

server_name www.nan.com;
access_log /usr/local/nginx/logs/www.nan.com.log;
error_log /usr/local/nginx/logs/www.nan.com.err;

listen  443 ssl;

ssl_buffer_size 4k;
ssl_certificate  /usr/local/nginx/cert/1_gw.nan_bundle.crt;  #在docker啟動鏡像的時候掛載證書目錄; /opt/nginx/vert
ssl_certificate_key /usr/local/nginx/cert/2_gw.nan.com.cn.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;

location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://gw_ma;
}

}

 

4.2 日志文件目錄:mdkir -p /opt/nginx/logs

5.啟動容器

參考:docker run -d –name=nginx02 -p 9999:80 -v /opt/nginx/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf -v /opt/nginx/conf/vhost/:/usr/local/nginx/conf/vhost/ -v /opt/nginx/logs/:/usr/local/nginx/logs/ xx.xx.xx.xx/library/nginx:v2

贊(0)
分享到: 更多 (0)
網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
日韩精品成人一区二区三区| 一本久久A久久免费精品不卡 | 亚洲va精品中文字幕| 日韩一级精品视频在线观看| 亚洲成人国产精品| 日韩亚洲国产综合高清| 国产精品视频免费一区二区三区| 91亚洲精品麻豆| 99re6热视频精品免费观看| 久久精品亚洲日本佐佐木明希| 成人午夜精品无码区久久| 久久精品亚洲福利| 国产伦精品一区二区三区视频金莲 | 欧美日韩精品SUV| 国产精品网站在线观看| 在线观看日韩精品| 精品一区二区三区免费毛片爱| 性欧洲精品videos| 久久精品成人无码观看56| 麻豆精品成人免费国产片| 国产在线不卡午夜精品2021| 亚洲精品自在在线观看| 国产成人麻豆亚洲综合无码精品| 不卡精品国产_亚洲人成在线| 久久国产精品视频| 久久久久久国产精品美女| 久久精品女人天堂AV麻| 久久精品一区二区影院| 久久久久久亚洲精品不卡| 中文字幕无码精品亚洲资源网| 国产伦精品一区二区三区视频金莲| 国产va免费精品| 国产精品99久久精品爆乳| 国产精品香蕉在线观看| 国产精品无码国模私拍视频| 精品国产青草久久久久福利| 久久www免费人成精品香蕉| 中文字幕精品在线观看| 精品久久久久久亚洲| 久久国产精品亚洲一区二区| 十八18禁国产精品www|