您的位置:首页 > 运维架构 > Nginx

安装nginx实录

2015-10-26 23:53 656 查看
其实安装nginx是一个简单的过程,但再简单的过程,只有亲身体验了,才能更好的理解,这就是实践出真理。好了,废话少说,开始吧。

为了有一个干净的初始化环境,特地上阿里云买了一个云主机,懒得安装linux系统的,这种方法不错。不过,最初始化的干净环境,最好留个快照,方便多次试验。

主要就3条命令

#configure 命令做了大量的“幕后”工作,包括检测操作系统内核、所需的依赖包是否安装、参数的解析、生成一些C源码文件、Makefile文件等。由于configure涉及的参数实在是太多了,记住几个就很不错。
#  --prefix=PATH 安装部署后的目录
#  --sbin-path=PATH 可执行文件的存放路径
#  --conf-path=PATH  配置文件路径

# make 根据 Makefile文件编译Nginx,并生成目标文件、最终的二进制文件

# make install 根据./configure 执行时的参数将nginx部署到指定的安装目录,包括相关目录的建立、二进制文件、配置文件的复制

./configure --prefix=/usr/local/nginx --sbin-path=/sbin --conf-path=/etc
make
make install


1.在./configure这一步就报错了,看到错误不要着急,仔细看提示。

./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.

解决办法:

缺少PCRE包,那就去下载一个吧

wget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.bz2 
tar -jxvf pcre-8.37.tar.bz2

make && make install


发现初始化的干净系统,真是太纯洁了,我们得按照./configure提示的错误,依赖包一个个都安装吧,耐心耐心

# 这些包的路径留着,以后省的再去找。
# 安装程序的方法都很简单,只需tar再make再make install即可,所以省去后面3步

wget http://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz


接下来很简单了,就make 和 make install

备注:

#在make时,报错如下。错误原因:makefile里面的文件依赖关系有问题,找不到依赖包

[root@iZ283rmolcfZ nginx-1.9.5]# make make: *** No rule to make target `build', needed by `default'.  Stop.


无法启动:

[root@iZ283rmolcfZ nginx-1.9.5]# /usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

# 解决方法:
[root@iZ283rmolcfZ lib64]# cd /lib64
[root@iZ283rmolcfZ lib64]# ll libpcre*
lrwxrwxrwx. 1 root root     16 Aug 14  2014 libpcre.so.0 -> libpcre.so.0.0.1
-rwxr-xr-x  1 root root 183816 Sep  7  2012 libpcre.so.0.0.1
# 在redhat 64位机器上, nginx可能读取的pcre文件为/lib64/libpcre.so.1文件.
[root@iZ283rmolcfZ lib64]# ln -s libpcre.so.0.0.1 libpcre.so.1

[root@iZ283rmolcfZ zlib-1.2.8]# ln -s /usr/local/nginx/sbin/nginx /bin/nginx
[root@iZ283rmolcfZ zlib-1.2.8]# nginx
[root@iZ283rmolcfZ zlib-1.2.8]# ps -ef | grep nginx
root      8002     1  0 23:12 ?        00:00:00 nginx: master process nginx
nobody    8003  8002  0 23:12 ?        00:00:00 nginx: worker process
root      8005 24780  0 23:13 pts/1    00:00:00 grep nginx

# 成功安装好 Nginx


使用yum等的来安装会方便,但是就失去了这样亲手一步步安装的乐趣,(*^__^*) 嘻嘻……
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: