nginx是C语言开发,建议在linux上运行,现在我使用的是centos6.8座位安装环境。
PCRE(PerlCompartible Regular Expressions)是一个Prel库,包括perl兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库
zlib库提供了很多压缩和解压的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
apt-get install build-essential
apt-get install libtool
进入解压的nginx-1.8.1目录下执行 configure文件:
使用命令:
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
注意:如果出现这个错误
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl= option.
解决办法:
apt-get install openssl
apt-get install libssl-dev
然后:make
再然后:make install
就好了
也可以直接:
1)下载 wget http://nginx.org/download/nginx-1.8.1.tar.gz
2) 解压 tar -zxvf nginx-1.8.1.tar.gz
3)cd nginx-1.8.1
4)./configure --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
5)make && make install
root 4260 0.0 0.1 44628 1148 ? Ss 02:55 0:00 nginx: master process ./nginx
nobody 4261 0.0 0.1 45076 1732 ? S 02:55 0:00 nginx: worker process
root 4325 0.0 0.0 103328 892 pts/0 S+ 03:06 0:00 grep nginx
./nginx -s reload
修改配置文件后不用重启nginx,直接执行上命令,就可以刷新配置生效
查看防火墙状态:service iptables status
关闭命令: service iptables stop
永久关闭防火墙:chkconfig iptables off
如果无效,可以使用以下命令:
将iptables和selinux关闭
以下4条命令清除iptables的配置
iptables -F
iptables -F -t nat
iptables -X
iptables -X -t nat
setenforce 0 #关闭selinux
或者使用命令:
vi /etc/sysconfig/iptables
在文件中将涉及的80端口打开
添加:-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
然后:service iptables restart
如果还存在问题,可以根据如下链接解决:
http://h2ofly.blog.51cto.com/6834926/1324588