服务器 \ linux \ CentOS6.5下Nginx1.7.4安装记录

CentOS6.5下Nginx1.7.4安装记录

总点击187
简介:版权声明:本文为testcs_dn(微wx笑)原创文章,非商用自由转载-保持署名-注明出处,谢谢。https://blog.csdn.net/testcs_dn/article/details/39233569

版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/39233569

1.环境准备

yum -y install gcc gcc-c++ autoconf automake make

CentOS6.5下Nginx1.7.4安装记录


yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 


不执行以上两项安装的话,就可能会遇到下面我的安装过程中遇到的情况:


到此页面下载自己想要的版本:

http://nginx.org/en/download.html

左侧为Linux版本,右侧为Windows版本


使用以下命令下载文件:wget http://nginx.org/download/nginx-1.7.4.tar.gz


解压文件:tar -zxvf nginx-1.7.4.tar.gz 


切换目录:cd nginx-1.7.4

配置:./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 ,他作用是让ngnix支持rewrite功能

使用命令安装:yum install pcre-devel.i686


输入y,回车


最后提示Complete,说明安装成功:


再执行./configure

还是提示同样的错误;

执行命令查找PCRE的安装位置:file -name pcre

得到的是:./auto/lib/pcre


根据提示在后面添加参数指定Path

执行命令:./configure --with-pcre=./auto/lib/pcre

提示如下信息:

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

 

还缺少zlib library信息!

执行以下命令安装:yum -y install make zlib zlib-devel gcc-c++ libtool

安装成功之后,再执行命令:./configure --with-pcre=./auto/lib/pcre

最后的提示信息如下:


应该是配置成功了,执行以下命令安装:

make && make install

提示以下错误:


该装的都装了,还是无法安装,最后执行以下命令解决问题:

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

执行之后再执行:./configure

再执行:make && make install

安装完成!


记住上图中的一些目录位置!

修改配置文件:

切换目录:cd /usr/local/nginx/conf

修改文件:vi nginx.conf

主要是修改server配置节的内容,按字母i进入编辑模式


按ESC键,退出编辑模式,按冒号键“:”进入命令模式,输入“wq”然后回车,保存并退出;

 

切换到sbin目录:cd /usr/local/nginx/sbin

启动Nginx:./nginx

开放防火墙端口:

/sbin/iptables -I INPUT -p tcp --dport 88 -j ACCEPT

/etc/init.d/iptables save

 

打开浏览器,输入以下地址访问吧:

http://你的服务器IP:88/

看到以下信息了吗?


我是看到了,看不到的朋友继续努力吧!


注意:我在虚拟机中安装的时候遇到了类似以下错误:

./configure auto/unix: No such file or directory


当我使用“mkdir auto/unix”之后,还是提示类似的错误,但目录名又变了。

纠结了好久,后来发现是解压的时候就有好多文件没有解压出来,判断应该是安装包压缩文件坏了,

所以解压的时候就少了好多的文件或目录,重新下载一个解压安装问题就解决了。


配置Nginx开机启动,vi /etc/rc.d/rc.local

在文件末尾添加“/usr/local/nginx/sbin/nginx”


Nginx常用命令:

重新加载配置文件:/usr/local/nginx/sbin/nginx -s reload

停止Nginx服务:/usr/local/nginx/sbin/nginx -s stop

其它Nginx命令:

/usr/local/nginx/sbin/nginx -h

nginx version: nginx/1.7.5

Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:

-?,-h : this help

-v : show version and exit

-V : show version and configure options then exit

-t : test configuration and exit

-q : suppress non-error messages during configuration testing

-s signal : send signal to a master process: stop,quit,reopen,reload

-p prefix : set prefix path (default: /usr/local/nginx/)

-c filename : set configuration file (default: conf/nginx.conf)

-g directives : set global directives out of configuration file

文件权限问题:

有可能因为目录、文件权限过高,导致Nginx无权访问文件,可以通过以下命令修改权限:

chmod -R 777 ./uploadfile


登录后自动展开

意见反馈 常见问题 官方微信 返回顶部