1.安装编译环境以及第三方开发包。
[root@VM_0_16_centos ~]# yum -y install gcc gcc-c++
[root@VM_0_16_centos ~]# yum -y install pcre pcre-devel
[root@VM_0_16_centos ~]# yum -y install zlib zlib-devel
[root@VM_0_16_centos ~]# yum -y install openssl openssl-devel
Gcc-c++:源代码编译环境。
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
Zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
2.把nginx源码包上传到服务器,并解压到指定位置(我直接解压到当前目录)。
[root@VM_0_16_centos ~]# tar -zxvf nginx-1.9.5.tar.gz
参数解释:tar -zxvf(解压命令,z:表示此压缩包是被 gzip 压缩过的,所以解压时需要用 gunzip 解压,x: 从 tar 包中把文件提取出来,v : 显示详细信息,f:指定被处理的文件)。
3.进入解压的目录。
[root@VM_0_16_centos ~]# cd nginx-1.9.5/
[root@VM_0_16_centos nginx-1.9.5]#
4.configure命令对安装软件进行配置。
[root@RedHat tmp]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-http_ssl_module
./configure是源代码安装的第一步,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系。
5.编译。
[root@VM_0_16_centos nginx-1.9.5]# make
[root@VM_0_16_centos nginx-1.9.5]# make install
6.安装完成后检验配置文件是否正确 nginx -t
[root@VM_0_16_centos nginx-1.9.5]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] mkdir() "/tmp/nginx/client_body" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
[root@VM_0_16_centos nginx-1.9.5]#
此时发现:
nginx: [emerg] mkdir() "/tmp/nginx/client_body" failed (2: No such file or directory)
需要建立没有的文件夹:
[root@VM_0_16_centos nginx-1.9.5]# mkdir -p /tmp/nginx/client_body
[root@VM_0_16_centos nginx-1.9.5]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
此时才正确安装。
7.启动nginx并检测是否启动。
[root@VM_0_16_centos nginx-1.9.5]# nginx
[root@VM_0_16_centos nginx-1.9.5]# netstat -antp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
已经完成正常启动。
8.浏览器访问服务器。
Perfect,顺利完成。
第一次写,勿喷