一.nginx的基本操作
1.语法
nginx安装路径下/sbin/nginx --启动nginx
以下操作需要在"nginx安装路径/sbin/"执行命令
./nginx -s quit --退出nginx
./nginx -s reload --重启配置文件
./nginx -v --查看版本信息
./nginx -t --查看配置文件所在的目录
./nginx -h --查看帮助信息
2.范例
二.nginx模块的指令
1.1 nginx的nginx.conf配置文件语法
cd nginx安装路径/conf 切换到指定路径
daermon on|off 是否是守护线程启动nginx,on为开启,off为关
master_process on|off 是否开启多线程模式,on为开启,off为关
worker_processes number 开启多个nginx进程,默认开启数为1
inciude 包含文件名 包含文件,注意:文件名不需要写后缀名
errorlog 文件名称 [debug|info|notice|error|crit]
错误异常日志记录,[]里面是可选级别
location 访问路径 设置访问路径
1.2查找配置路径
1.3设置demon、master_process的范例【不推荐修改】
1.4设置开启的进程数
1.5设置访问路径
2.1nginx的logs/nginx.pid语法
cd nginx安装路径/logs文件夹 切换到指定路径
cat nginx.pid 查看nginx进程
2.2范例
三.http模块的指令
1.1nginx的nginx.conf配置文件语法
alias 别名 设置别名
keepalive_timeout [time] 设置超时连接时间,默认时间75s,time单位为秒
listen 端口号 监听端口
resolver_timeout [time] 解析超时时间,默认值为30s
root 访问的绝对路径 设置服务器资源的访问路径
1.2范例一【别名设置】
1.3设置超时连接
1.4监听端口
1.5设置服务器资源访问路径
四.server模块的指令
1.nginx的nginx.conf配置文件语法
server_name 服务器名称 设置服务器名称
listen 端口号 设置监听的端口号
charset 字符集 设置字符集
2.范例
五.nginx负载均衡模块
1.语法
#负载均衡池
upstream backend{
server backend1.example.com weight=5,
server backend2.example.com:8081
server unix:/tmp/backend3
}
#负载均衡跳转处理
server{
location /{
proxy_pass http:backend;
}
}
2.范例
3.指令
指令 |
作用 |
使用位置 |
默认值 |
ip_hash |
根据ip地址分发请求 |
upstream |
none |
upstream 访问请求{ server1 server2 } |
负载均衡池 目的是分发服务器的访问请求 |
upstream |
无 |
weight=数值 |
指分发服务器资源访问请求的连接数 |
upstream |
1 |
mail_fails=数值 |
指分发服务器资源访问请求的最大失败数 |
upstream |
1 |
fail_timeout=30s(时间) |
指分发服务器资源访问请求的超时时间 |
upstream |
10s |
upstream name {…} |
指分发服务器资源 |
upstream |
无 |
六.HTTP访问模块
1.语法
指令 |
作用 |
使用位置 |
默认值 |
deny ip地址 |
禁止ip地址访问 |
http,server,location,limit_execpt |
no |
allow ip地址段 |
允许一段ip地址访问 |
http,server,location,limit_execpt |
no |
denyall |
禁止所有IP地址访问 |
http,server,location,limit_execpt |
no |
2.范例