二、Nginx了解目录及其编译参数

rpm -ql nginx 可查看所有nginx安装目录

路径类型作用
/etc/logrotate.d/nginx配置文件Nginx 日志轮转,用于logrotate服务的日志切割
/etc/nginx目录、配置文件Nginx主配置文件
/etc/nginx/nginx.conf
/etc/nginx/conf.d
/etc/nginx/fastcgi_params目录、配置文件Nginx主配置文件
/etc/nginx/uwsgi_params
/etc/nginx/scgi_params
/etc/nginx/koi-utf配置文件编码转换映射转化文件
/etc/nginx/koi-win
/etc/nginx/win-utf
/etc/nginx/mime.types配置文件设置http协议的Content-type与扩展名对应关系
/usr/lib/systemd/system/nginx-debug.service配置文件用于配置出系统守护进程管理器管理方式
/usr/lib/systemd/system/nginx.service
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib64/nginx/modules目录Nginx模块目录
/etc/nginx/modules
/usr/sbin/nginx命令Nginx服务的启动管理的终端命令
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.16.0文件、目录Nginx的手册和帮助文件
/usr/share/doc/nginx-1.16.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/var/cache/nginx目录Nginx的缓存目录
/var/log/nginx目录Nginx的日志目录

安装编译参数
命令:

nginx -V  

编译选项 作用

--prefix=/etc/nginx                            安装目的目录或路径
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib64/nginx/modules
--conf-path=/etv/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock

--http-client-body-temp-path=/var/cache/nginx/client_temp            执行对应模块时,Nginx所保留的临时性文件
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp

--user=nginx                         设定Nginx进程启动的用户和组用户
--group=nginx


--with-cc-opt=parameters		     设定额外的参数将被添加到CFLAGS变量

--with-ld-opt=parameters			 设置附加的参数,链接系统库

nginx 默认页面 /usr/share/nginx/html

如果有修改配置文件,可以使用:
//systemctl启动方式

1.设置开机自启动
systemctl enable nginx.service 
2.启动nginx服务
systemctl start nginx.service
3.停止开机自启动
systemctl disable nginx.service
4.查看服务当前状态
systemctl status nginx.service
5.重新启动服务
systemctl restart nginx.service  ,   最好 使用  systemctl reload nginx.service 进行重启
6.查看所有已启动的服务
systemctl list-units --type=service


systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

*代表某个服务的名字,如http的服务名为httpd

Nginx 默认配置语法及其含义
1.Nginx.conf 文件

user   				设置nginxg服务的系统使用用户
worker_processes	工作进程数(和CPU核数设置一样就可以了)
error_log 			nginx的错误日志
pid					nginx服务启动时候的PID


events 模块
worker_connections   每个进程允许最大连接数
user                 工作进程数

2.Nginx日志类型

  1. error_log
  2. access_log

3.Nginx 变量

HTTP 请求变量 -

  1. arg_PARAMETER :request请求的对应的参数 http_HEADER
  2. request请求里面的header来进行输出 sent_http_HEADER
  3. 服务端返回给客户的response的header,对应的头信息 进行输出

内置变量 - Nginx 内置的

内置变量内容

自定义变量 - 自己定义

例:
在 nginx.conf 修改log配置,

$remote_addr:表示客户端的地址 
$remote_user :用户端请求nginx认证的用户名,不开启认证模块,不会记录
$time_local :nginx的时间
$request :请求行
$status : respons的请求状态
$body_bytes_sent : 表示服务端响应用户端的body内的大小
$http_referer:上一级页面的url记录	
$http_user_agent :http头信息
$http_x_forwarded_for :头信息

在这里插入图片描述
对应的是请求头信息里面的
在这里插入图片描述
当你修改了配置文件,可以使用:

nginx -t -c /etc/nginx/nginx.conf  

检查配置是否正确,然后使用:

nginx -s reload -c /etc/nginx/nginx.conf

重新加载配置文件,达到成功修改
执行 curl http://127.0.0.1 命令
这是为了打印在log 上,测试刚才是否配置成功,接下来使用命令将日志打印出来:

tail -n 200 /var/log/nginx/access.log

在这里插入图片描述
网上有很多关于log_format的的语法配置,百度一下很多,就不过多描述了

请多多指教!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值