Docker容器内部安装Nginx

摘要:Docker容器下环境安装Nginx笔记,中途遇到些问题希望高手指教。

1、下载依赖包和Nginx

wgethttp://zlib.net/zlib-1.2.11.tar.gz

wgethttps://www.openssl.org/source/openssl-1.0.2l.tar.gz

wgethttps://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz

wgethttp://nginx.org/download/nginx-1.8.0.tar.gz

2、解压缩并按照openssl开发包

[root@7e0590732abb ng]# ll

total 9060

-rw-r--r--. 1 root root 832104 Apr 21 2015 nginx-1.8.0.tar.gz

-rw-r--r--. 1 root root 5365054 May 25 13:09 openssl-1.0.2l.tar.gz

-rw-r--r--. 1 root root 409600 Jul 4 13:42 pcre-8.38.tar.gz

-rw-r--r--. 1 root root 2053336 Jan 12 2016 pcre-8.38.tar.gz.1

-rw-r--r--. 1 root root 607698 Jan 15 18:13 zlib-1.2.11.tar.gz

[root@7e0590732abb ng]# tar -zvxf openssl-1.0.2l.tar.gz

[root@7e0590732abb ng]# tar -zvxf pcre-8.38.tar.gz

[root@7e0590732abb ng]# tar zvxf zlib-1.2.11.tar.gz

[root@7e0590732abb ng]# tar -zvxf nginx-1.8.0.tar.gz

[root@7e0590732abb ng]# ll

total 8676

drwxr-xr-x. 8 1001 1001 4096 Apr 21 2015 nginx-1.8.0

-rw-r--r--. 1 root root 832104 Apr 21 2015 nginx-1.8.0.tar.gz

drwxr-xr-x. 21 root root 4096 Jul 4 13:55 openssl-1.0.2l

-rw-r--r--. 1 root root 5365054 May 25 13:09 openssl-1.0.2l.tar.gz

drwxr-xr-x. 7 1169 1169 4096 Nov 23 2015 pcre-8.38

-rw-r--r--. 1 root root 2053336 Jan 12 2016 pcre-8.38.tar.gz

drwxr-xr-x. 14 501 games 4096 Jan 15 17:36 zlib-1.2.11

-rw-r--r--. 1 root root 607698 Jan 15 18:13 zlib-1.2.11.tar.gz

安装openssl开发包:

[root@7e0590732abb include]# yum -y install openssl-devel

3、安装make工具,后面编译安装时会用到。

[root@7e0590732abb nginx-1.8.0]# yum -y install make

configure: error: You need a C++ compiler for C++ support.

make[1]: *** [/ng/pcre-8.38/Makefile] Error 1

make[1]: Leaving directory `/ng/nginx-1.8.0'

make: *** [build] Error 2

4、在安装make时提示需要安装C++

[root@7e0590732abb nginx-1.8.0]# yum -y install gcc gcc-c++

5、编译安装

[root@7e0590732abb nginx-1.8.0]# ./configure --sbin-path=/ng/nginx-1.8.0/nginx --conf-path=/ng/nginx-1.8.0/nginx.conf --pid-path=/ng/nginx-1.8.0/nginx.pid --with-http_ssl_module --with-pcre=/ng/pcre-8.38 --with-zlib=/ng/zlib-1.2.11 --with-openssl=/ng/openssl-1.0.2l

checking for OS

........

............

Configuration summary

using PCRE library: /ng/pcre-8.38

using OpenSSL library: /ng/openssl-1.0.2l

md5: using OpenSSL library

sha1: using OpenSSL library

using zlib library: /ng/zlib-1.2.11

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/ng/nginx-1.8.0/nginx"

nginx configuration prefix: "/ng/nginx-1.8.0"

nginx configuration file: "/ng/nginx-1.8.0/nginx.conf"

nginx pid file: "/ng/nginx-1.8.0/nginx.pid"

nginx error log file: "/usr/local/nginx/logs/error.log"

nginx http access log file: "/usr/local/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"

[root@7e0590732abb nginx-1.8.0]# make

make -f objs/Makefile

......

.........

make[2]: Leaving directory/ng/openssl-1.0.2l'

Operating system: x86_64-whatever-linux2

You need Perl 5.

make[1]: *** [/ng/openssl-1.0.2l/.openssl/include/openssl/ssl.h] Error 1

make[1]: Leaving directory/ng/nginx-1.8.0'

make: *** [build] Error 2

[root@7e0590732abb nginx]# pwd

/usr/local/nginx

[root@7e0590732abb nginx]# cd sbin

[root@7e0590732abb sbin]# ls

nginx

[root@7e0590732abb sbin]# ./nginx

[root@7e0590732abb sbin]# ss -tnl | nginx

bash: nginx: command not found

bash: ss: command not found

[root@7e0590732abb sbin]# yum -y install netstat

Loaded plugins: fastestmirror, ovl

Loading mirror speeds from cached hostfile

base: mirror.bit.edu.cn

extras: mirror.bit.edu.cn

updates: mirror.bit.edu.cn ...... .......... Complete! [root@7e0590732abb sbin]# netstat -an | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

6、因为上面的容器在启动时没有映射端口,容器保存后映射端口并运行。

[root@docker01 ~]# docker run -it -p 80:80 --name ngx00 -v /ng:/ng c367c7a906d8 /bin/bash

[root@a4f55a7586e4 sbin]# ./nginx

[root@a4f55a7586e4 sbin]# netstat -an | grep 80

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

7、使用宿主机IP+80端口访问正常

问题:

在编译安装时仍然有报错,如果高手看到帮忙分析一下,目前还没找到解决方案。

用云栖社区APP,舒服~

原文链接

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容