安装Nginx-1.5.4——Nginx-1.5.4源码安装教程(二)


关键词

Nginx Nginx-1.5.4 安装

摘要

本系列教程介绍在Linux(CentOS 5.8)上安装Nginx-1.5.4的全过程。第二篇,介绍下载Nginx-1.5.4的Tarball(.tar.gz)源文件,然后进行conifgure、make、make install的全过程。

本系列教程介绍在Linux(CentOS 5.8)上安装Nginx-1.5.4的全过程。第二篇,介绍下载Nginx-1.5.4的Tarball(.tar.gz)源文件,然后进行conifgure、make、make install的全过程。

安装前的准备工作


使用tarball源代码方式安装Nginx-1.5.4之前,需要安装一系列组件,详情请见:http://www.splaybow.com/post/nginx-1-5-4-source-install-1-components.html

如果您选择yum或apt-get这种包管理器安装,请绕路。

下载Nginx-1.5.4


按照鸟哥(VBird)使用源码安装软件的思路,我们将Tarball文件下载到/usr/local/src/目录下。

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.5.4.tar.gz

这个是从Nginx官网(www.nginx.net或www.nginx.org上下载时看到链接)。

解压缩nginx-1.5.4.tar.gz


接下来将nginx-1.5.4.tar.gz解压到当前目录,即/usr/local/src/目录,解压后将生成一个nginx-1.5.4目录。

[root@localhost src]# tar -zxvf nginx-1.5.4.tar.gz

配置Nginx-1.5.4


进入到nginx-1.5.4目录,运行./configure,进行编译前的配置。这个命令可以带很多参数,其中一个最重要的是安装路径 --prefix,我们将它设置为/usr/lcoal/nginx-1.5.4。为什么这个安装目录要带个版本号呢?因为我考虑到后面如果要升级Nginx,那我还可以编译安装一个nginx-1.5.5什么的。同时我可以做一个符号链接nginx,让它指向nginx-1.5.4,等Nginx升级后,我再将它指向nginx-1.5.5,这样岂不是看起来更完美?!

其它的参数可以使用 ./configure --help 命令来查看,根据需要进行指定。

[root@localhost src]# cd nginx-1.5.4
[root@localhost nginx-1.5.4]# ./configure --prefix=/usr/local/nginx-1.5.4

在配置过程中,我们可能看不懂它在搞什么东东,但configure运行结束时,我们可以看看Configuration summary:

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx-1.5.4"
  nginx binary file: "/usr/local/nginx-1.5.4/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx-1.5.4/conf"
  nginx configuration file: "/usr/local/nginx-1.5.4/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx-1.5.4/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx-1.5.4/logs/error.log"
  nginx http access log file: "/usr/local/nginx-1.5.4/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"

上面部分说使用了哪个组件或库文件,下面讲配置过程中做了一些什么事情。

编译Nginx-1.5.4


编译很简单,就是直接执行一下这个目录下的make脚本。虽然命令很简单,但make的过程是很漫长的。

[root@localhost nginx-1.5.4]# make

安装Nginx-1.5.4


只要编译成功,安装也是很容易的,就是直接执行一下这个目录下的make install命令。make install应该是一闪而过的结束掉。

[root@localhost nginx-1.5.4]# make install

这样在/usr/local/目录下就会多出一个nginx-1.5.4目录了。

运行Nginx-1.5.4


root@localhost local]# ls
bin  etc  games  include  lib  libexec  nginx-1.5.4  sbin  share  src
[root@localhost local]# cd nginx-1.5.4/
[root@localhost nginx-1.5.4]# ls
conf  html  logs  sbin
[root@localhost nginx-1.5.4]# cd sbin/
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# nginx
-bash: nginx: command not found
[root@localhost sbin]# ./nginx

如果没有出现任何错误,表现nginx已经成功执行起来了。然后我们看看进程:

[root@localhost sbin]# ps -aux | grep nginx

使用ps进程查看工具会发现如下两条记录:
root     31470  0.0  0.0   4128   524 ?        Ss   11:19   0:00 nginx: master process ./nginx
nobody   31471  0.0  0.0   4300   856 ?        S    11:19   0:00 nginx: worker process

再使用netstat端口查看工具,会发现如下记录:
[root@localhost sbin]# netstat -antp
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      31470/nginx    

至此,Nginx-1.5.4已经安装成功了!后续我们将介绍如何进一步的配置Nginx-1.5.4,敬请关注!

洪哥笔记网站原创,欢迎转载,转载请加上原文链接:http://www.splaybow.com/post/nginx-1-5-4-source-install-2-tarball.html

 

要饭二维码

洪哥写文章很苦逼,如果本文对您略有帮助,可以扫描下方二维码支持洪哥!金额随意,先行谢过!大家的支持是我前进的动力!

文章的版权


如果您在服务器运维、网络管理、网站或系统开发过程有需要提供收费服务,请加QQ:8771947!十年运维经验,帮您省钱、让您放心!
亲,如果有需要,先存起来,方便以后再看啊!加入收藏夹的话,按Ctrl+D

« 安装Nginx所需的环境组件——Nginx-1.5.4源码安装教程(一) Nginx搭建虚拟主机 »