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@7e0590732abbng]#ll

total9060

-rw-r--r--.1rootroot832104Apr212015nginx-1.8.0.tar.gz

-rw-r--r--.1rootroot5365054May2513:09openssl-1.0.2l.tar.gz

-rw-r--r--.1rootroot409600Jul413:42pcre-8.38.tar.gz

-rw-r--r--.1rootroot2053336Jan122016pcre-8.38.tar.gz.1

-rw-r--r--.1rootroot607698Jan1518:13zlib-1.2.11.tar.gz

[root@7e0590732abbng]#tar-zvxfopenssl-1.0.2l.tar.gz

[root@7e0590732abbng]#tar-zvxfpcre-8.38.tar.gz

[root@7e0590732abbng]#tarzvxfzlib-1.2.11.tar.gz

[root@7e0590732abbng]#tar-zvxfnginx-1.8.0.tar.gz

[root@7e0590732abbng]#ll

total8676

drwxr-xr-x.8100110014096Apr212015nginx-1.8.0

-rw-r--r--.1rootroot832104Apr212015nginx-1.8.0.tar.gz

drwxr-xr-x.21rootroot4096Jul413:55openssl-1.0.2l

-rw-r--r--.1rootroot5365054May2513:09openssl-1.0.2l.tar.gz

drwxr-xr-x.7116911694096Nov232015pcre-8.38

-rw-r--r--.1rootroot2053336Jan122016pcre-8.38.tar.gz

drwxr-xr-x.14501games4096Jan1517:36zlib-1.2.11

-rw-r--r--.1rootroot607698Jan1518:13zlib-1.2.11.tar.gz

安装openssl开发包:

[root@7e0590732abbinclude]#yum-yinstallopenssl-devel

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

[[email protected]]#yum-yinstallmake

configure:error:YouneedaC++compilerforC++support.

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

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

make:***[build]Error2

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

[[email protected]]#yum-yinstallgccgcc-c++

5、编译安装

[[email protected]]#./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

checkingforOS

........

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

Configurationsummary

usingPCRElibrary:/ng/pcre-8.38

usingOpenSSLlibrary:/ng/openssl-1.0.2l

md5:usingOpenSSLlibrary

sha1:usingOpenSSLlibrary

usingzliblibrary:/ng/zlib-1.2.11

nginxpathprefix:"/usr/local/nginx"

nginxbinaryfile:"/ng/nginx-1.8.0/nginx"

nginxconfigurationprefix:"/ng/nginx-1.8.0"

nginxconfigurationfile:"/ng/nginx-1.8.0/nginx.conf"

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

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

nginxhttpaccesslogfile:"/usr/local/nginx/logs/access.log"

nginxhttpclientrequestbodytemporaryfiles:"client_body_temp"

nginxhttpproxytemporaryfiles:"proxy_temp"

nginxhttpfastcgitemporaryfiles:"fastcgi_temp"

nginxhttpuwsgitemporaryfiles:"uwsgi_temp"

nginxhttpscgitemporaryfiles:"scgi_temp"

[[email protected]]#make

make-fobjs/Makefile

......

.........

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

Operatingsystem:x86_64-whatever-linux2

YouneedPerl5.

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

make[1]:Leavingdirectory/ng/nginx-1.8.0'

make:***[build]Error2

[root@7e0590732abbnginx]#pwd

/usr/local/nginx

[root@7e0590732abbnginx]#cdsbin

[root@7e0590732abbsbin]#ls

nginx

[root@7e0590732abbsbin]#./nginx

[root@7e0590732abbsbin]#ss-tnl|nginx

bash:nginx:commandnotfound

bash:ss:commandnotfound

[root@7e0590732abbsbin]#yum-yinstallnetstat

Loadedplugins:fastestmirror,ovl

Loadingmirrorspeedsfromcachedhostfile

base:mirror.bit.edu.cn

extras:mirror.bit.edu.cn

updates:mirror.bit.edu.cn................Complete![root@7e0590732abbsbin]#netstat-an|grep80tcp000.0.0.0:800.0.0.0:*LISTEN

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

[root@docker01~]#dockerrun-it-p80:80--namengx00-v/ng:/ngc367c7a906d8/bin/bash

[root@a4f55a7586e4sbin]#./nginx

[root@a4f55a7586e4sbin]#netstat-an|grep80

tcp000.0.0.0:800.0.0.0:*LISTEN

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

screenshot

问题:

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

screenshot

用云栖社区APP,舒服~

相关推荐