主題: CentOS6.7上安裝nginx1.8.0 環境準備: 1.gcc-c++ 示例:yum install gcc-c++ 安裝:gcc-c++ gcc-c++編譯工具 2.PCRE(Perl Compatible Regular Expressions) 示例:yum install -y pcre pcre-devel 安裝:pcre和pcre-devel PCRE(Perl Compatible Regular Expressions)是一個 Perl 庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,因此須要在 linux 上安裝 pcre 庫。pcre-devel 是使用 pcre 開發的一個二次開發庫。nginx 也須要此庫。 3.zlib 示例:yum install -y zlib zlib-devel 安裝:zlib和zlib-devel 4.OpenSSL 示例:yum install -y openssl openssl-devel 安裝:openssl和openssl-devel OpenSSL是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、經常使用的密鑰和證書封裝管理功能及 SSL 協議,並提供豐富的應用程序供測試或其它目的使用。nginx 不只支持 http 協議,還支持 https(即在 ssl 協議上傳輸 http),因此須要在 linux安裝 openssl 庫 安裝步驟: 在nginx解壓目錄中,./configure&make&make install 壓縮包存放: /root/develop/ 解壓目錄: /root/develop/nginx-1.8.0 [root@heima01 nginx-1.8.0]# pwd /root/develop/nginx-1.8.0 [root@heima01 nginx-1.8.0]# ls auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src 配置幫助: 1.help方式 示例:# ./configure --help 2.info方式 示例:# info configure help方式: [root@heima01 nginx-1.8.0]# ./configure --help --help print this message --prefix=PATH set installation prefix --sbin-path=PATH set nginx binary pathname --conf-path=PATH set nginx.conf pathname --error-log-path=PATH set error log pathname --pid-path=PATH set nginx.pid pathname --lock-path=PATH set nginx.lock pathname --user=USER set non-privileged user for worker processes --group=GROUP set non-privileged group for worker processes --build=NAME set build name --builddir=DIR set build directory info方式: [root@heima01 /]# info configure File: configure.info, Node: Top, Next: Introduction, Up: (dir) GNU configure and build system ****************************** The GNU configure and build system. * Menu: * Introduction:: Introduction. * Getting Started:: Getting Started. * Files:: Files. * Configuration Names:: Configuration Names. * Cross Compilation Tools:: Cross Compilation Tools. * Canadian Cross:: Canadian Cross. * Cygnus Configure:: Cygnus Configure. * Multilibs:: Multilibs. * FAQ:: Frequently Asked Questions. * Index:: Index. configure參數: ./configure \ --prefix=/usr \ 指向安裝目錄 --sbin-path=/usr/sbin/nginx \ 指向(執行)程序文件(nginx) --conf-path=/etc/nginx/nginx.conf \ 指向配置文件 --error-log-path=/var/log/nginx/error.log \ 指向log --http-log-path=/var/log/nginx/access.log \ 指向http-log --pid-path=/var/run/nginx/nginx.pid \ 指向pid --lock-path=/var/lock/nginx.lock \ (安裝文件鎖定,防止安裝文件被別人利用,或本身誤操做。) --user=nginx \ --group=nginx \ --with-http_ssl_module \ 啓用ngx_http_ssl_module支持(使支持https請求,需已安裝openssl) --with-http_flv_module \ 啓用ngx_http_flv_module支持(提供尋求內存使用基於時間的偏移量文件) --with-http_stub_status_module \ 啓用ngx_http_stub_status_module支持(獲取nginx自上次啓動以來的工做狀態) --with-http_gzip_static_module \ 啓用ngx_http_gzip_static_module支持(在線實時壓縮輸出數據流) --http-client-body-temp-path=/var/tmp/nginx/client/ \ 設定http客戶端請求臨時文件路徑 --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 設定http代理臨時文件路徑 --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 設定http fastcgi臨時文件路徑 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 設定http uwsgi臨時文件路徑 --http-scgi-temp-path=/var/tmp/nginx/scgi \ 設定http scgi臨時文件路徑 --with-pcre 啓用pcre庫 實際使用的configure參數: ./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi 問題: 描述:系統須要安裝PCRE library 方案:安裝pcre-devel ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option. [root@heima01 nginx-1.8.0]# yum search pcre Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.cqu.edu.cn * extras: mirrors.cn99.com * updates: mirrors.163.com ================================================================================ N/S Matched: pcre ================================================================================= pcre-devel.i686 : Development files for pcre pcre-static.i686 : Static library for pcre pcre.i686 : Perl-compatible regular expression library [root@heima01 nginx-1.8.0]# yum install pcre-devel.i686 Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * extras: mirrors.cn99.com * updates: mirrors.163.com Resolving Dependencies --> Running transaction check ---> Package pcre-devel.i686 0:7.8-7.el6 will be installed --> Finished Dependency Resolution 問題: 描述:HTTP gizp模塊須要zlib庫 方案:安裝zlib-devel ./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option. [root@heima01 nginx-1.8.0]# yum list installed | grep zlib zlib.i686 1.2.3-29.el6 @anaconda-CentOS-201508042139.i386/6.7 搜索zlib-devel包: [root@heima01 nginx-1.8.0]# yum search zlib Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.cqu.edu.cn * extras: mirrors.cn99.com * updates: mirrors.163.com ================================================================================ N/S Matched: zlib ================================================================================= jzlib.i686 : JZlib re-implementation of zlib in pure Java jzlib-demo.i686 : Examples for jzlib jzlib-javadoc.i686 : Javadoc for jzlib perl-Compress-Raw-Zlib.i686 : Low-Level Interface to the zlib compression library perl-Compress-Zlib.i686 : A module providing Perl interfaces to the zlib compression library perl-IO-Zlib.i686 : Perl IO:: style interface to Compress::Zlib zlib.i686 : The zlib compression and decompression library zlib-devel.i686 : Header files and libraries for Zlib development zlib-static.i686 : Static libraries for Zlib development perl-IO-Compress-Zlib.i686 : Perl interface to allow reading and writing of gzip and zip data 安裝zlib-devel包: [root@heima01 nginx-1.8.0]# yum install -y zlib-devel.i686 Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.cqu.edu.cn * extras: mirrors.cn99.com * updates: mirrors.163.com Resolving Dependencies --> Running transaction check ---> Package zlib-devel.i686 0:1.2.3-29.el6 will be installed --> Finished Dependency Resolution 查看是否安裝了zlib-devel包: [root@heima01 nginx-1.8.0]# yum list installed | grep zlib Existing lock /var/run/yum.pid: another copy is running as pid 6999. Another app is currently holding the yum lock; waiting for it to exit... The other application is: PackageKit Memory : 25 M RSS ( 72 MB VSZ) Started: Wed May 29 05:29:04 2019 - 00:06 ago State : Sleeping, pid: 6999 zlib.i686 1.2.3-29.el6 @anaconda-CentOS-201508042139.i386/6.7 zlib-devel.i686 1.2.3-29.el6 @base ./configure執行結果: Configuration summary + using system PCRE library + OpenSSL library is not used + using builtin md5 code + sha1 library is not found + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/var/run/nginx/nginx.pid" nginx error log file: "/var/log/nginx/error.log" nginx http access log file: "/var/log/nginx/access.log" nginx http client request body temporary files: "/var/temp/nginx/client" nginx http proxy temporary files: "/var/temp/nginx/proxy" nginx http fastcgi temporary files: "/var/temp/nginx/fastcgi" nginx http uwsgi temporary files: "/var/temp/nginx/uwsgi" nginx http scgi temporary files: "/var/temp/nginx/scgi" [root@heima01 sbin]# ./nginx nginx: [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory) 執行命令目錄爲: /usr/local/nginx/sbin 啓動nginx: [root@heima01 ~]# cd /usr/local/nginx/ [root@heima01 nginx]# ls conf html sbin [root@heima01 nginx]# cd sbin [root@heima01 sbin]# ls nginx [root@heima01 sbin]# ./nginx 啓動後查看進程: 示例:# ps aux | grep nginx [root@heima01 nginx-1.8.0]# ps aux | grep nginx root 3000 0.0 0.0 3200 524 ? Ss 04:45 0:00 nginx: master process ./nginx nobody 3001 0.0 0.1 3404 1184 ? S 04:45 0:00 nginx: worker process root 3230 0.0 0.0 4420 760 pts/2 S+ 05:14 0:00 grep nginx 查看防火牆過濾規則: 示例:# service iptables status [root@heima01 nginx-1.8.0]# service iptables status Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306 4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 5 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 8 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited 查看網絡監聽: 示例:# netstat -ntlp [root@heima01 nginx-1.8.0]# netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1585/rpcbind tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3000/nginx tcp 0 0 0.0.0.0:43315 0.0.0.0:* LISTEN 1642/rpc.statd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1832/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1681/cupsd tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2746/sshd tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 2970/sshd tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 2797/java tcp 0 0 :::8009 :::* LISTEN 2797/java tcp 0 0 :::3306 :::* LISTEN 1990/mysqld tcp 0 0 :::111 :::* LISTEN 1585/rpcbind tcp 0 0 :::8080 :::* LISTEN 2797/java tcp 0 0 :::22 :::* LISTEN 1832/sshd tcp 0 0 ::1:631 :::* LISTEN 1681/cupsd tcp 0 0 ::1:6010 :::* LISTEN 2746/sshd tcp 0 0 ::1:6011 :::* LISTEN 2970/sshd tcp 0 0 :::49662 :::* LISTEN 1642/rpc.statd 關閉nginx: 方式1:./nginx -s stop 方式2:./nginx -s quit 錯誤示例: [root@heima01 sbin]# ./nginx -s exit nginx: invalid option: "-s exit" 重啓nginx: 示例:./nginx -s reload 執行命令目錄爲: /usr/local/nginx/sbin