CentOS 安装nginx

在安装nginx前,需要确保系统安装了g++、gcc、openssl-devel、pcre-devel和zlib-devel软件。安装必须软件:

复制代码 代码如下:


[root@admin  /]#yum install gcc-c++

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


[root@admin/] nginx-1.2.1]$ yum install -y pcre-devel 


如果运行出错:./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库:yum install zlib-devel


[root@admin/] nginx-1.2.1]$ yum install zlib-devel 


检查系统安装的Nginx:

复制代码 代码如下:


[root@admin  local]# find -name nginx

./nginx

./nginx/sbin/nginx

./nginx-1.2.6/objs/nginx  

卸载原有的Nginx

复制代码 代码如下:


[root@admin  /]# yum remove nginx  

安装 

将安装包文件上传到/usr/local中执行以下操作:

复制代码 代码如下:


[root@admin local]# cd /usr/local

[root@admin local]# tar -zxv -f nginx-1.9.6.tar.gz

[root@admin local]# rm -rf nginx-1.9.6.tar.gz

[root@admin local]# mv nginx-1.9.6 /usr/local/nginx

[root@admin local]# cd /usr/local/nginx

[root@admin nginx]# ./configure --prefix=/usr/local/nginx

[root@admin nginx]# make

[root@admin nginx]# make install  


############################################################################################

编译nginx时出现如下错误提示:

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


#yum install openssl

#yum install openssl-devel


如果要开启htts ssl 安全链接

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module


make 

make 

############################################################################################


配置

复制代码 代码如下:


#修改防火墙配置: 

[root@admin nginx-1.2.6]# vi + /etc/sysconfig/iptables

#添加配置项 

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

#重启防火墙 

[root@admin nginx-1.2.6]# service iptables restart  

启动

复制代码 代码如下:


#方法1

[root@admin nginx-1.2.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

#方法2

[root@admin nginx-1.2.6]# cd /usr/local/nginx/sbin

[root@admin sbin]# ./nginx

停止

复制代码 代码如下:


#查询nginx主进程号 

ps -ef | grep nginx

#停止进程 

kill -QUIT 主进程号 

#快速停止 

kill -TERM 主进程号 

#强制停止 

pkill -9 nginx

重启

[root@admin local]# /usr/local/nginx/sbin/nginx -s reload

 

测试

复制代码 代码如下:


#测试端口 

netstat –na|grep 80

#浏览器中测试 

http://ip:80


转载于:https://my.oschina.net/u/2616024/blog/625710

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值