1.环境准备
yum -y install gcc gcc-c++ autoconf automake make
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命令:
[plain] view plaincopy
/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
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com