Nginx 核心配置文件和常用命令

1 核心配置

  1. 设置worker进程的用户,指的linux中的用户,会涉及到nginx操作目录或文件的一些权限,默认为 nobody

    user root;
    
  2. worker进程工作数设置,一般来说CPU有几个,就设置几个,或者设置为N-1也行

    worker_processes 1;
    
  3. nginx 日志级别 debug | info | notice | warn | error | crit | alert | emerg ,错误级别从左到右越来越大

  4. 设置nginx进程 pid

    pid logs/nginx.pid;
    
  5. 设置工作模式

    events {
    	# 默认使用epoll
    	use epoll;
    	# 每个worker允许连接的客户端最大连接数
    	worker_connections 10240;
    }
    
  6. http 是指令块,针对http网络传输的一些指令配置

    http {
    }
    
  7. include 引入外部配置,提高可读性,避免单个配置文件过大

    include mime.types;
    
  8. 设定日志格式, main 为定义的格式名称,如此 access_log 就可以直接使用这个变量了

    参数名参数意义
    $remote_addr客户端ip
    $remote_user远程客户端用户名,一般为:’-’
    $time_local时间和时区
    $request请求的url以及method
    $status响应状态码
    $body_bytes_send响应客户端内容字节数
    $http_referer记录用户从哪个链接跳转过来的
    $http_user_agent用户所使用的代理,一般来时都是浏览器
    $http_x_forwarded_for通过代理服务器来记录客户端的ip
  9. sendfile 使用高效文件传输,提升传输性能。启用后才能使用 tcp_nopush ,是指当数据表累积一定大小后才发送,提高了效率。

    sendfile on;
    tcp_nopush on;
    
  10. keepalive_timeout 设置客户端与服务端请求的超时时间,保证客户端多次请求的时候不会重复建立新的连接,节约资源损耗。

    #keepalive_timeout 0;
    keepalive_timeout 65;
    

2 常用命令

2.1 停止

1 暴力停止(不推荐

[root@localhost ~]# /usr/local/nginx/sbin
[root@localhost sbin]# ./nginx -s stop

2 等待请求结束,再关闭(只针对http 推荐

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

2.2 验证配置文件

[root@localhost sbin]# ./nginx -t 

2.3 查看版本号和具体信息

[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.16.1
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi

2.4 提示命令

[root@localhost sbin]# ./nginx -h
nginx version: nginx/1.16.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: /usr/local/nginx/conf/nginx.conf)
  -g directives : set global directives out of configuration file

2.5 重新加载配置文件

[root@localhost sbin]# ./nginx -s reload

2.5 指定核心配置文件

[root@localhost sbin]# ./nginx -c test.conf

3 相关信息

  • **博文不易,辛苦各位猿友点个关注和赞,感谢 **

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小P聊技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值