nginx介绍(一)

一、下载

地址:

nginx: download

二、安装

1、安装gcc环境

yum install gcc-c++

2、安装pcre库,用于校验正则表达式

#yum -y install pcre pcre-devel
yum -y install pcre*

3、zlib压缩和解压的依赖

#yum -y install zlib zlib-devel
yum -y install zlib*

4、SSL(Https必备)

#yum -y install openssl openssl-devel
yum -y install openssl*

5、解压

tar -zxvf nginx-*

注:解压后得到的是源码,需要编译后才能安装

6、在Nginx目录输入如下命令进行配置,目的是为了创建Makefile文件

#执行命令
#prefix= 指向安装目录(编译安装)
#conf-path= 指向配置文件(nginx.conf)
#error-log-path= 指向错误日志目录
#pid-path= 指向pid文件(nginx.pid)
#http-log-path= 设定access log路径
#with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
#with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
#with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)


./configure \
--prefix=/usr/local/tool/nginx-1.22.0 \
--conf-path=/usr/local/tool/nginx-1.22.0/nginx.conf  \
--error-log-path=/usr/local/tool/nginx-1.22.0/logs/error.log \
--pid-path=/usr/local/tool/nginx-1.22.0/logs/nginx.pid  \
--http-log-path=/usr/local/tool/nginx-1.22.0/logs/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module

7、make编译

make

 8、安装

make install

9、进入sbin目录启动Nginx

#启动

./nginx

#暴力关闭,有http请求时也会关闭

./nginx -s stop

#优雅关闭,有http请求时不会关闭,等结束后才会结束

./nginx -s  quit

#重新加载

./nginx -s reload

#检查配置

./nginx -t

#查看版本

./nginx -v

#查看版本和配置信息

./nginx -V

注:

(1)、在云服务器安装,需要开启默认的防火墙80

(2)、在虚拟机需要关闭防火墙

(3)本地需要关闭防火墙

三、进程模型

master进程:主进程

worker进程:工作进程

worker进程

修改nginx.conf中worker_processes为2

1、检查配置文件是否有问题

./nginx -t

 这样代表正常

2、重新加载

./nginx -s reload

现在就出现了两个worker 

四、配置结构

1、user  nobody;

指定用户,默认是nobody,如果需要一些文件的使用权限的话,可以指定用户。

2、worker_processes

工作进程的数量

3、error_log 

error_log  logs/error.log  notice;

日志的路径以及级别

级别:debug 、info、 notice、warn、error、crit

注:在安装时已经指定了日志路径:-- error-log-path

4、pid

主要存放Nginx的进程号

常遇见的问题:

(1)、pid文件打开失败

可能的原因是文件或目录不存在,重新创建文件然后执行以下命令:

./nginx -s reload

(2)、pid无效

通过命名重新指定nginx.conf文件路径,命令如下:

#重新指定nginx.conf路径
./nginx -c  路径
#重新加载
./nginx -s reload

注:在安装时已经指定了路径:--pid-path

5、events 事件相关配置

操作模式:

默认是epoll(liunx)

use epoll

连接数配置(默认是1024)

worker_connections  10240

6、http

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值