閱讀635 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Docker容器內部安裝Nginx

1、下載依賴包和Nginx
wget https://zlib.net/zlib-1.2.11.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
wget https://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端口訪問正常
screenshot

問題:
在編譯安裝時仍然有報錯,如果高手看到幫忙分析一下,目前還沒找到解決方案。
screenshot

最後更新:2017-07-05 14:02:27

  上一篇:go  Java程序員可以從事的崗位有哪些?
  下一篇:go  java 在線編輯模版 代碼編輯器 兼容手機平板PC freemaker 靜態引擎 網站源碼