centos64位安装nginx

本文详细介绍如何在Linux环境下安装Nginx,并配置其运行环境。包括安装必要的依赖软件、下载Nginx源码包、编译安装过程及解决常见问题的方法。同时,还介绍了如何配置防火墙规则以允许HTTP流量通过。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装在/opt/nginx/中


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

yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

2.检查是否有nginx 

find -name nginx    (有的话,卸载原有的nginx ,yum remove nginx)

3.下载安装

现在/opt下新建文件夹:nginx

wget http://nginx.org/download/nginx-1.5.9.tar.gz

tar -zxv -f nginx-1.5.9.tar.gz

cd nginx-1.5.9

./configure --prefix=/opt/nginx (设置配置信息)

make 

make install

在配置信息的时候出现:



安装pcre-devel解决问题
yum -y install pcre-devel

还有可能出现:

错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解决办法:

yum -y install openssl openssl-devel

4.配置防火墙

#修改防火墙配置: 

vi + /etc/sysconfig/iptables

#添加配置项

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

#重启防火墙 : service iptables restart

第三步:

启动ngnix

/opt/nginx/sbin/nginx   start

或者 ./nginx

停止:

#查询nginx主进程号 
ps -ef | grep nginx
#停止进程 
kill -QUIT 主进程号 
#快速停止 
kill -TERM 主进程号 
#强制停止 
pkill -9 nginxd

重启:

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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值