centos安装nginx

本文详细介绍在CentOS 6.8环境下安装Nginx的过程,包括必要的依赖安装、源码下载、编译配置等步骤,并提供了启动、停止、重启Nginx服务的方法。

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

Nginx是一个高性能的HTTP和反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好

安装

下面我们来在centos6.8的服务器上安装一下nginx服务,首先安装nginx服务需要安装很多依赖关系

[root@koby2 ~]#yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel  autoconf automake


这里我们要下载一下openssl


[root@koby2 ~]#wget -O openssl.tar.gz -c https://github.com/openssl/openssl/archive/OpenSSL_1_0_2k.tar.gz     #具体版本可根据实际情况选择

[root@koby2 ~]#tar zxf openssl.tar.gz
[root@koby2 ~]#mv openssl-OpenSSL_1_0_2k/ openssl

接下来我们要下载nginx 在这个网站下载需要的nginx版本http://nginx.org/en/download.html
[root@koby2 ~]#wget -c https://nginx.org/download/nginx-1.11.13.tar.gz
[root@koby2 ~]#tar -zxvf nginx-1.11.13.tar.gz
[root@koby2 ~]#cd nginx-1.11.13
[root@koby2 nginx-1.11.13]#./configure  --prefix=/usr/local/nginx/ --with-openssl=/root/openssl --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-file-aio --with-http_realip_module

[root@koby2 nginx-1.11.13]#make && make install

我们需要配置防火墙的端口

[root@koby2 ~]# vi /etc/sysconfig/iptables
在里面添加 
-A INPUT -m state --state NEW -m tcp -p tcp  --dport 80 -j ACCEPT
然后重启防火墙 
[root@koby2 ~]# service iptables restart
这时我们来启动nginx来看看效果
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@koby2 ~]# netstat -ntlp|grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      11086/nginx
可以看到nginx的端口已经在监听了 我们先在浏览器上查看下
在浏览器上输入http://192.168.1.1/   #本机ip
可以看到如下页面
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

这样我们的nginx就安装好了 我们再开看下改如何关闭nginx
[root@koby2 ~]# /usr/local/nginx/sbin/./nginx -s stop
重启命令如下
[root@koby2 ~]# /usr/local/nginx/sbin/nginx -s reload

检查配置文件是否正确很有帮助的一个命令
[root@koby2 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值