Linux制作绿色版nginx

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuwei0376/article/details/85078200

在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文件夹;
3、进入源码目录,并执行configure命令

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

–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-green/”
nginx binary file: “/opt/nginx-green//sbin/nginx”
nginx modules path: “/opt/nginx-green//modules”
nginx configuration prefix: “/opt/nginx-green//conf”
nginx configuration file: “/opt/nginx-green//conf/nginx.conf”
nginx pid file: “/opt/nginx-green//logs/nginx.pid”
nginx error log file: “/opt/nginx-green//logs/error.log”
nginx http access log file: “/opt/nginx-green//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-green文件夹。
后续可基于此模板文件,做一些优化配置,即可用于docker内部署。

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

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

猜你喜欢

转载自blog.csdn.net/liuwei0376/article/details/85078200