nginx之基于centos快速安装入门

一、安装

1、ngnix官网(http://nginx.org/)下载.tart.gz格式的安装包

安装包:nginx-1.15.5.tar.gz

2、安装依赖包

由于nginx中的功能是模块化的,而模块化又依赖于一些软件包才能使用,因此在安装nginx之前要安装必要的软件包

常见软件包说明:

软件包说明
pcre-devel为nginx模块提供正则表达式库
zlib-devel为nginx模块提供数据压缩用的函数库
openssl-devel为nginx模块提供密码算法、证书以及SSL协议等
[root@localhost ~]# yum -y install pcre-devel zlib-devel openssl-devel

多学一招:devel包和非devel包的区别

   非devel是一般普通的软件包,而devel包则一般会包括头文件、静态库甚至源码,若仅仅使用软件安装非devel包即可

3、ngnix的编译安装

(1)解压 nginx-1.15.5.tar.gz 安装包

[root@localhost ~]# tar -zxvf nginx-1.15.5.tar.gz

(2)切换到nginx解压目录

[root@localhost ~]# cd nginx-1.15.5

(3)配置nginx的编译选项,指定nginx的安装目录及安装模块

[root@localhost nginx-1.15.5]# ./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module

说明:

--prefix:指定软件安装目录

--with-http_ssl_module:安装了http_ssl_module模块相关功能

上面命令的中第一行和第二行 \  斜杠是命令换行符

......
checking for PCRE JIT support ... found
checking for zlib library ... found
......

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/local/nginx"
  nginx binary file: "/usr/local/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/local/nginx/modules"
  nginx configuration prefix: "/usr/local/local/nginx/conf"
  nginx configuration file: "/usr/local/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

从./configure的输出中能看出nginx的安装后生产的文件及文件位置等

(4)通过make编译和安装 

[root@localhost nginx-1.15.5]# make && make install

 

二、nginx启动和停止

1、启动nginx服务

[root@localhost ~]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ./nignx

2、停止nginx服务

(1)立即停止

[root@localhost sbin]# ./nignx -s stop

(2)从容停止(等待当前工作进程完成当前工作任务后再停止)

[root@localhost sbin]# ./nignx -s quit

(3)kill

[root@localhost ~]# kill -9 nginx主进程ID
[root@localhost ~]# killall nginx

3、其他常用命令

命令说明
nginx -s reload重启
nginx -s reopen打开日志文件
nginx -c /某个目录/nginx.conf以某个nginx配置文件启动nginx服务
nginx -t检测配置文件是否正确
nginx -t -c /某个目录/nginx.conf检测某个nginx配置文件是否真确
nginx -v显示版本信息
nginx -V显示版本信息和编译选项

三、测试查看nignx是否启动成功

1、查看端口看nginx是否启动,nginx默认端口号为80

[root@localhost ~]# netstat -tuln

如果出现如下,代表启动nginx的80端口成功

 

2、通过ps -ef | grep nginx 查看 nginx 服务是否启动

[root@localhost ~]# ps -ef | grep nginx

3、浏览器输入nginx服务器的Ip地址查看,出现如下代表安装成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值