nginx服务器搭建和配置(nginx怎么搭配配置服务器)

发布日期:2024-06-07 10:00:57     手机:https://m.xinb2b.cn/wenda/news3054.html    违规举报
核心提示:Nginx安装配置 以core模块的server指令为例: Syntax: server {…}Default:一Context:http Syntax代表语法规则,Default代表默认值,Context代表在哪个模块中使用。

nginx服务器搭建和配置(nginx怎么搭配配置服务器)

Nginx安装配置

以core模块的server指令为例:

Syntax: server {…}Default:一Context:http

Syntax代表语法规则,Default代表默认值,Context代表在哪个模块中使用。

规则:

    用〃#”表示注释 每行配置的结尾需要加上分号(漏了分号会导致无法启动) 如果配置项值中包括语法符号,比如空格符,那么需要使用单引号或双引号括住配置项值,否则Nginx会报语法错误 单位简写,当指定空间大小时,可以使用的单位包括: K或者k(千字节 KiloByte KB),M或者m(兆字节 MegaByte MB)比如
gzip_buffers 48k; client_max_body_size 64M;

  当指定时间时,可以使用的单位包括:ms (毫秒),s (秒),m (分钟),h (小 时),d (天),w (周,包含7天),M (月,包含30天),v (年,包含365天)。

例如

expires 10y; proxy_read_timeout 600; client_body_timeout 2m;
    基本配置项
#user administrator administrators; #配置用户或者组,默认为 nobody nobody。#worker_processes 2;#允许生成的进程数,默认为1#pid /nginx/pid/nginx.pid; #指定 nginx 进程运行文件存放地址error_log log/error.log debug;#制定日志路径,级别。这个设置可以放入全局块,http 块,server 块,级别以此为∶ debug|infolnotice|warn|error|crit|alertlemerg events{accept_mutex on; #设置网络连接序列化,防止惊群现象发生,默认为 on multi accept on; #设置一个进程是否同时接受多个网络连接,默认为 off#use epoll;#事件驱动模型,selectpollkqueuelepoll|resig|/dev/polleventport worker_connections 1024;#最大连接数,默认为 512}http { include mime.types;#文件扩展名与文件类型映射表default_type application/octet-stream; #默认文件类型,默认为 text/plain#access_log off; #取消服务日志log_format myFormat \'$remote_addr-$remote_user [$time_local] $request $status $body _bytes_sent$http referer $http user agent $http x forwarded for\'; #自定义格式 access_log log/access.log myFormat; #combined 为日志格式的默认值sendfile on; #允许 sendfile 方式传输文件,默认为 off,可以在 http 块,server 块,location 块。 sendfile_max_chunk 100k;#每个进程每次调用传输数量不能大于设定的值,默认为 0,即不设上限。keepalive timeout 65;#连接超时时间,默认为75s,可以在 http,server,location 块。upstream mysvr { server 127.0.0.1:7878;server 192.168.10.121∶3333 backup;#热备}error_page 404 https∶//www.baidu.com; #错误页 server {keepalive_requests 120; #单连接请求上限次数。 listen 4545; #监听端口 server_name 127.0.0.1; #监听地址location ~*^.+${#请求的 url 过滤,正则匹配,~为区分大小写,~*为不区分大小写。#root path; #根目录#index vv.txt; #设置默认页proxy_pass http∶//mysvr;#请求转向 mysvr 定义的服务器列表 deny 127.0.0.1; #拒绝的 ip allow 172.18.5.54;#允许的 ip}}} 3.Nginx基本命令

在sbin目录下,加上./

4.Nginx 日志

4.1 日志路径和内容

  如果我们需要知道Nginx转发的请求的情况,比如来源IP、访问的URL、终端类型 等等,可以在Nginx中记录访问日志。如果Nginx运行发生了异常,也可以通过异常日 志找到原因。

  日志路径在安装根路径logs目录下。日志主要有两种,access.log是访问日志, error.log是服务错误日志。access日志的内容格式是可以定制的。

4.2 日志配置

配置文件:nginx-reverse.conf

log_format main\'$remote_user[$time_local] $http_x_Forwarded_for $remote_addr $request‘\'$http_x_forwarded_for \'\'$upstream_addr \'‘ups_resp_time: $upstream_response_time‘ ‘request_time: $request_time n\';

配置了日志内容格式之后,继续配置日志:
可以使用的变量:

access_log path [format [buffer=size] [gzip[=level]] [flush=time][i仁condition]];

总结一下,主要的模块是access log. Iog_format.

 
 
本文地址:https://wenda.xinb2b.cn/news3054.html,转载请注明出处。

推荐图文
推荐问答知道
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  违规举报  |  蜀ICP备18010318号-4  |  百度地图  | 
Processed in 0.096 second(s), 91 queries, Memory 0.47 M