CentOS6.7上安装nginx1.8.0

时间:2021-01-20 11:07:06
主题:
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