源码编译安装方法
1、上传包nginx-1.10.0.tar.gz至服务端
# 解压到工作目录
[root@template ~]# tar xf nginx-1.10.0.tar.gz -C /usr/local/src/
# 切换至Nginx目录下,找到configure
[root@template ~]# cd /usr/local/src/
[root@template src]# ll
total 0
drwxr-xr-x. 8 1001 1001 158 Apr 26 2016 nginx-1.10.0
[root@template src]# cd nginx-1.10.0/
[root@template nginx-1.10.0]# ll
total 668
drwxr-xr-x. 6 1001 1001 4096 Apr 2 17:25 auto
-rw-r--r--. 1 1001 1001 262619 Apr 26 2016 CHANGES
-rw-r--r--. 1 1001 1001 400302 Apr 26 2016 CHANGES.ru
drwxr-xr-x. 2 1001 1001 168 Apr 2 17:25 conf
-rwxr-xr-x. 1 1001 1001 2481 Apr 26 2016 configure
drwxr-xr-x. 4 1001 1001 72 Apr 2 17:25 contrib
drwxr-xr-x. 2 1001 1001 40 Apr 2 17:25 html
-rw-r--r--. 1 1001 1001 1397 Apr 26 2016 LICENSE
drwxr-xr-x. 2 1001 1001 21 Apr 2 17:25 man
-rw-r--r--. 1 1001 1001 49 Apr 26 2016 README
drwxr-xr-x. 9 1001 1001 91 Apr 2 17:25 src
2、安装rpm包,查看他的脚本文件
[root@node01 ~]# yum install nginx-1.10.0-1.el7.ngx.x86_64.rpm -y
3、在rpm包上查看所属组信息
[root@node01 ~]# id nginx
uid=305(nginx) gid=305(nginx) groups=305(nginx)
4、创建用户信息
[root@template ~]# groupadd nginx -r -g 498
[root@template ~]# useradd nginx -r -u 498 -g 498 -c "nginx user" -d /etc/nginx -s /sbin/nologin
5、创建日志文件目录
# 默认情况下是没有的
[root@template nginx-1.10.0]# ll /var/log/nginx
ls: cannot access /var/log/nginx: No such file or directory
[root@template nginx-1.10.0]# mkdir /var/log/nginx
6、可以用此选项查看编译过程需要的参数文件
[root@template nginx-1.10.0]# ./configure --help
7、编译,但是没有装一些环境,在编译中报错中缺什么安装什么包
[root@template nginx-1.10.0]# ./configure \
> --prefix=/etc/nginx \
> --sbin-path=/usr/sbin/nginx \
> --modules-path=/usr/lib64/nginx/modules \
> --conf-path=/etc/nginx/nginx.conf \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --pid-path=/var/run/nginx.pid \
> --lock-path=/var/run/nginx.lock \
> --user=nginx --group=nginx \
> --with-http_ssl_module \
> --with-threads
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
8、解决第一个报错信息,缺少C环境
[root@template nginx-1.10.0]# yum install gcc gcc-c++ make -y
9、调出命令继续编译,解决报错
./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@template nginx-1.10.0]# yum install pcre-devel -y
10、继续编译
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
[root@template nginx-1.10.0]# yum install openssl-devel -y
11、再次编译,最后make && make install
[root@template nginx-1.10.0]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-threads
[root@template ng