设为首页 收藏本站
查看: 521|回复: 0

[经验分享] docker Dockerfile构建nginx1.12.0

[复制链接]
累计签到:29 天
连续签到:1 天
发表于 2018-11-12 06:59:20 | 显示全部楼层 |阅读模式
  Dockerfile文件详情
  FROM centos:6.7
  MAINTAINER from hanye131 hz7726@163.com
  RUN yum clean all && \
  rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-* && \
  yum install -y epel-release && \
  rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 && \
  yum makecache && \
  yum install -y pcre-devel openssl-devel zlib-devel gd-devel tar gcc wget git supervisor
  RUN groupadd --system www && \
  useradd --system --gid www www && \
  mkdir -p {/var/log/wwwlogs,/var/run/nginx,/var/lock}
  RUN wget -c http://nginx.org/download/nginx-1.12.0.tar.gz && \
  git clone https://github.com/cuber/ngx_http_google_filter_module.git && \
  git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module.git && \
  git clone https://github.com/aperezdc/ngx-fancyindex.git
  RUN tar xf nginx-1.12.0.tar.gz && \
  cd nginx-1.12.0 && \
  ./configure --prefix=/usr/local/nginx \
  --user=www --group=www \
  --error-log-path=/var/log/wwwlogs/error.log \
  --http-log-path=/var/log/wwwlogs/access.log \
  --pid-path=/var/run/nginx/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --with-pcre \
  --with-ipv6 \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_v2_module \
  --with-http_realip_module \
  --with-http_gzip_static_module \
  --with-http_stub_status_module \
  --with-http_mp4_module \
  --with-http_image_filter_module \
  --with-http_addition_module \
  --http-client-body-temp-path=/usr/local/nginx/client/ \
  --http-proxy-temp-path=/usr/local/nginx/proxy/ \
  --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
  --http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
  --http-scgi-temp-path=/usr/local/nginx/scgi \
  --add-module=../ngx_http_google_filter_module \
  --add-module=../ngx_http_substitutions_filter_module \
  --add-module=../ngx-fancyindex && \
  make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && \
  rm -rf ../{ngx_http*,ngx-fancyindex,nginx-1.12.0*}
  ADD nginx.conf /usr/local/nginx/conf/nginx.conf
  ADD nginx.sh /nginx.sh
  RUN chmod +x /nginx.sh
  VOLUME ["/home/wwwroot"]
  EXPOSE 80 443
  ENTRYPOINT ["/nginx.sh"]
  CMD ["nginx"]
  nginx.sh详情
  #!/bin/sh
  #########################################################################
  # File Name: nginx.sh
  # Author: hanye131
  # Email: hz7726@163.com
  # Version: 1.0
  #########################################################################
  PATH=/bin:/usr/local/nginx/sbin:$PATH
  Nginx_Install_Dir=/usr/local/nginx
  set -e
  if [ -n "$TIMEZONE" ]; then
  rm -rf /etc/localtime && \
  ln -s /usr/share/zoneinfo/$TIMEZONE /etc/localtime
  fi
  if [ "${1:0:1}" = '-' ]; then
  set -- nginx "$@"
  fi
  if [ -z "$DATA_DIR" ]; then
  DATA_DIR=/home/wwwroot
  fi
  sed -i "s@/home/wwwroot@$DATA_DIR@" $Nginx_Install_Dir/conf/nginx.conf
  mkdir -p ${DATA_DIR}
  [ ! -f "$DATA_DIR/index.html" ] && echo '

  hellow docker nginx
  ' > $DATA_DIR/index.html
  chown -R www.www $DATA_DIR
  CPU_num=$(awk '/processor/{i++}END{print i}' /proc/cpuinfo)
  if [ "$CPU_num" == '2' ];then
  sed -i 's@^worker_processes.*@worker_processes 2;\nworker_cpu_affinity 10 01;@' $Nginx_Install_Dir/conf/nginx.conf
  elif [ "$CPU_num" == '3' ];then
  sed -i 's@^worker_processes.*@worker_processes 3;\nworker_cpu_affinity 100 010 001;@' $Nginx_Install_Dir/conf/nginx.conf
  elif [ "$CPU_num" == '4' ];then
  sed -i 's@^worker_processes.*@worker_processes 4;\nworker_cpu_affinity 1000 0100 0010 0001;@' $Nginx_Install_Dir/conf/nginx.conf
  elif [ "$CPU_num" == '6' ];then
  sed -i 's@^worker_processes.*@worker_processes 6;\nworker_cpu_affinity 100000 010000 001000 000100 000010 000001;@' $Nginx_Install_Dir/conf/nginx.conf
  elif [ "$CPU_num" == '8' ];then
  sed -i 's@^worker_processes.*@worker_processes 8;\nworker_cpu_affinity 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001;@' $Nginx_Install_Dir/conf/nginx.conf
  else
  echo Google worker_cpu_affinity
  fi
  exec "$@" -g "daemon off;"
  nginx.xonf配置详情
  user www www;
  worker_processes auto;
  error_log /var/log/wwwlogs/error_nginx.log crit;
  pid /var/run/nginx.pid;
  worker_rlimit_nofile 51200;
  events {
  use epoll;
  worker_connections 51200;
  }
  http {
  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 50m;
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 120;
  server_tokens off;
  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 Compression
  gzip on;
  gzip_buffers 16 8k;
  gzip_comp_level 6;
  gzip_http_version 1.1;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types
  text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
  text/javascript application/javascript application/x-javascript
  text/x-json application/json application/x-web-app-manifest+json
  text/css text/plain text/x-component
  font/opentype application/x-font-ttf application/vnd.ms-fontobject
  image/x-icon;
  gzip_disable  "msie6";
  #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
  open_file_cache max=1000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;
  server {
  listen 80;
  server_name -;
  root /home/wwwroot;
  index index.html index.php index.jsp;
  access_log /var/log/wwwlogs/access_nginx.log combined;
  location /status {
  stub_status on;
  auth_basic "WebServer Status";
  }
  #        location ~ .*\.(php|php5)?$ {
  #            #fastcgi_pass remote_php_ip:9000;
  #            fastcgi_pass unix:/dev/shm/php-cgi.sock;
  #            fastcgi_index index.php;
  #            include fastcgi.conf;
  #        }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
  expires 30d;
  }
  location ~ .*\.(js|css)?$ {
  expires 7d;
  }
  }
  ##########################vhost#####################################
  include vhost/*.conf;
  }
  构建项目
  构建镜像容器
  docker build -t nginx_build:1.12.0 ./
  构建启动项目
  docker run -itd --name nginx_build -p 80:80 -p 443:443 -v $PWD/nginx:/home/wwwroot nginx_build:1.12.0
  docker images 查看项目
  docker ps 查看启动
  docker logs nginx_build 查看启动日志


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-633836-1-1.html 上篇帖子: Nginx详解(二)操作 下篇帖子: Nginx ~健康状态监测~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表