在docker化的部署方式中,时常需要一个轻量化的nginx系统,主要用于实现动静分离,实现路由转发,或部署静态资源(可类比web容器)。

轻量化的nginx,可以与静态资源一起,或接口服务一起,方便的打包进docker应用中。

nginx的windows版本就类似这种结构,然而在linux下似乎没有如下这种组织结构:

[root@5798e1897433 nginx]# ls -al
drwxr-xr-x 2 root root 4096 Dec 17 04:45 conf --nginx.conf配置文件
drwxr-xr-x 3 root root 4096 Dec 18 10:03 html --存放静态资源文件,或在root中指定到一个目录中
drwxr-xr-x 2 root root 4096 Dec 12 12:34 logs
drwxr-xr-x 2 root root 4096 Dec 12 06:49 sbin --NG二进制启动脚本,windows版本通过在外部

Nginx在日常使用中(这里主要指linux系统),主要通过以下两种方式安装:

1、各linux发行版的安装命令安装;
2、源码安装;

经过实验,发现如下步骤可以实现这个目标:

以下通过源码编译安装方式制作绿色版nginx软件:
1、在某个目录下(如/opt)下载nginx-1.14.2.tar.gz,解压;
2、/opt下创建nginx-green文件夹,注意此处如果的文件夹名称会被编译至二进制命令sbin/nginx文件中,导致后续使用时,如果nginx文件夹不是nginx-green,将报错,如下所示。

建议直接在/opt下新建nginx文件夹,生成绿色版文件后,在备份模板文件为nginx-green,拷贝模板至docker中时建议修改为nginx;

nginx: [alert] could not open error log file: open() "/opt/nginx-green//logs/error.log" failed (2: No such file or directory)
2019/01/16 14:03:52 [emerg] 7#0: open() "/opt/nginx-green//conf/nginx.conf" failed (2: No such file or directory)

说明
以下安装均在/opt/nginx目录下进行

3、进入源码目录,并执行configure命令

cd nginx-1.14.2;
./configure --prefix=/opt/nginx/

–prefix 用于指定nginx编译后的安装目录

Console中看到如下提示,已成功完成配置。

checking for PCRE library … found
checking for PCRE JIT support … found
checking for zlib library … found
creating objs/Makefile

Configuration summary

  • using system PCRE library
  • OpenSSL library is not used
  • using system zlib library

nginx path prefix: “/opt/nginx/”
nginx binary file: “/opt/nginx//sbin/nginx”
nginx modules path: “/opt/nginx//modules”
nginx configuration prefix: “/opt/nginx//conf”
nginx configuration file: “/opt/nginx//conf/nginx.conf”
nginx pid file: “/opt/nginx//logs/nginx.pid”
nginx error log file: “/opt/nginx//logs/error.log”
nginx http access log file: “/opt/nginx//logs/access.log”
nginx http client request body temporary files: “client_body_temp”
nginx http proxy temporary files: “proxy_temp”
nginx http fastcgi temporary files: “fastcgi_temp”
nginx http uwsgi temporary files: “uwsgi_temp”
nginx http scgi temporary files: “scgi_temp”

4、编译
make

5、安装
make install

如上步骤完成后,绿色版的nginx即制作完成,即为刚才创建的nginx文件夹。
后续可基于此模板文件,做一些优化配置,即可用于docker内部署。

进入到该文件夹nginx中,目录结果如下:

nginx
├── conf
│ ├── fastcgi.conf
│ ├── fastcgi.conf.default
│ ├── fastcgi_params
│ ├── fastcgi_params.default
│ ├── koi-utf
│ ├── koi-win
│ ├── mime.types
│ ├── mime.types.default
│ ├── nginx.conf
│ ├── nginx.conf.default
│ ├── scgi_params
│ ├── scgi_params.default
│ ├── uwsgi_params
│ ├── uwsgi_params.default
│ └── win-utf
├── html
│ ├── 50x.html
│ └── index.html
├── logs
│ ├── access.log
│ ├── error.log
│ └── nginx.pid
└── sbin
└── nginx

docker中部署时,需要注意,容器内,即使配过环境变量,也不能直接启动sbin目录下的nginx,需要携带目录启动,如下:
sbin/nginx

直接启动后,可看到如下进程:

[root@testxxx sbin]# ps -ef|grep nginx
root     18295     1  0 20:29 ?        00:00:00 nginx: master process ./nginx
nobody   18296 18295  0 20:29 ?        00:00:00 nginx: worker process
root     18304  6114  0 20:29 pts/0    00:00:00 grep --color=auto nginx

附加1:


一. 前期安装的nginx未添加ssl模块,无法支持配置https访问.
可能会报如下错误:
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /opt/nginx/conf/nginx.conf:36

解决方案:
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module

引用列表,致谢:

  • 关于给编译好的nginx,添加http_ssl_module模块及配置ssl证书

Linux制作绿色版nginx相关推荐

  1. Linux绿色版Nginx

    Linux绿色版Nginx 背景 ​ Nginx想必大家都比较熟悉了,这里就不做过多的诉述它的强大和用处了.上次在开发时,产品提出了一个需求:在不同网段的实现请求的转发和响应,最终讨论使用 nginx ...

  2. dockerfile安装yum_Docker镜像-基于DockerFile制作yum版nginx镜像

    Docker镜像-基于DockerFile制作yum版nginx镜像 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. DockerFile可以说是一种能被Docker程序解释的脚本, ...

  3. Ubuntu14下制作绿色版MariaDB_20160601_七侠镇莫尛貝

    Ubuntu14下制作绿色版Maria-DB_20160601_七侠镇莫尛貝 Ubuntu14下MariaDB常规的安装方法是:apt install mariadb-server. 绿色版Maria ...

  4. linux系统安装绿色版mysql

    linux安装压缩版mysql5.7 1.先使用以下命令检查是否已经安装了mysql rpm -qa | grep -i mysql 如果已经安装了,需要先卸载,再进行安装操作. 2.官网下载mysq ...

  5. CentOs7 安装绿色版Nginx并配置开机启动

    1.下载nginx 下载地址: http://nginx.org/en/download.html 2.安装编译需要的包支持 yum -y install gcc zlib zlib-devel pc ...

  6. linux 安装绿色版的tomcat

    一.下载免安装版Tomcat 打开Tomcat主页http://tomcat.apache.org/,下载Tomcat免安装版,我这里下载的是apache-tomcat-7.0.2.tar.gz. 二 ...

  7. linux模拟器 linux模拟器绿色版

    linux学习爱好者的首选工具,可以解压直接使用,文件大小还不到100M,真正方便好用 下载地址:http://www.ziddu.com/download/13939926/linux_mode.r ...

  8. 【lizhi125】Cameyo - 简单几步轻松制作单文件绿色版软件!

    当安装的东西越多,日积月累之后,Windows 就会运行得越来越慢,于是网络上绿色软件 (便携版软件) 特别的受欢迎.可是很多时候,在一些网站上下载的绿色软件会被偷偷加了病毒或木马,又或者自己需要的软 ...

  9. linux下制作codeblocks绿色版,并集成devhelp

    Codeblocks更新到12.11了,可是软件中心还是10.01的.在codeblocks的官网找了一下发现了ubnutu的ppa, sudo apt-add-repository ppa:pasg ...

最新文章

  1. java线程触发_java线程
  2. 【BZOJ】1013 [JSOI2008]球形空间产生器sphere
  3. VC++动态链接库(DLL)编程(四)――MFC扩展 DLL
  4. VB6+Winsock编写的websocket服务端
  5. 学python语言用什么软件-对于自学python的初学者来说,应该使用什么编辑工具?...
  6. Github标星59.7k:用动画的形式呈现解LeetCode题目的思路
  7. ASP.NET Core MVC – Form Tag Helpers
  8. android代码判断权限,安卓权限检测代码
  9. SpringMVC中注解@RequestBody和@ResponseBody的使用区别
  10. pdo mysql 事务_PHP PDO对象如何确定它是否已经存在于MySQL事务中?
  11. java中使用unzip_unzip命令_Linux unzip命令用法示例详解
  12. vue实现周日历切换(两种方式)
  13. 运用流体布局的html代码,div+css布局之流体浮动布局_html/css_WEB-ITnose
  14. 通过wait,notify等实现线程通讯
  15. 堆糖生活家喜欢的图片批量下载
  16. 使用D触发器完成带有异步清零clrn和同步使能wen的8位寄存器
  17. 从事SQL相关工作者可以成为数据科学家吗
  18. 十大领域五大过程组(上):你必须了解的项目管理常识
  19. 如何选择适合自己的自媒体平台?
  20. 浅谈数据库用户表结构设计,第三方登录

热门文章

  1. 问题解决 | 黑金AX7020使用Petalinux定制Linux系统遇到的坑
  2. Zadig 玩转亚马逊云科技全家桶
  3. 场景管理方法之BVH介绍
  4. 【XBEE手册】传输、寻址和路由(Transmission, addressing, and routing)
  5. 基于matlab的OFDM通信链路仿真,输出OFDM频谱,星座图,收发时域波形
  6. Xilinx ISE、Synplify、Modelsim之间的关系,为什么会存在比ISE更专业的FPGA开发工具?
  7. php分页类代码带分页样式效果(转)
  8. 如何学好python web开发_如何学好python web开发
  9. 台达PLC控制触摸屏的画面切换
  10. 玩赚你的网站-网站运营必备手册