首页 > 系统相关 >配置文件 proxy_set_header -发往后端服务器的请求头---- nginx日志设置级别调试技巧 - 长连接配置

配置文件 proxy_set_header -发往后端服务器的请求头---- nginx日志设置级别调试技巧 - 长连接配置

时间:2023-06-26 12:03:04浏览次数:64  
标签:set http log 配置文件 header nginx proxy 日志

http {
    include       mime.types;
    default_type  application/octet-stream; sendfile on;
    #tcp_nopush     on; #keepalive_timeout 0;
    keepalive_timeout  65; server_tokens off;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
                       '$upstream_addr $upstream_response_time $request_time ';
---------------------------------------------------------- 经典日志设置级别--得到关键情报

2、访问日志

[Access.log]
log_format main '$remote_addr '$status $upstream_status '"$http_user_agent" $ssl_protocol $ssl_cipher $upstream_addr ’
‘$request_time $upstream_response_time’;
---------------------------------------------------------- 经典日志设置级别--得到关键情报
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
                 '$request_time $request_length '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent"';
    access_log /var/logs/nginx/access.log main;

    keepalive_timeout  0;

参考: https://help.aliyun.com/document_detail/28988.html?spm=a2c4g.11186623.2.12.7a8018ceN8PjJk#reference-kv2-sr5-vdb

---------------------------------------------------------- 经典日志设置级别--得到关键情报
server {
    listen 80;
    server_name  paas.service.consul;

    client_max_body_size    512m;
    access_log  /data/bkdata/bkce/logs/nginx/paas_inner_access.log;

    # ============================ paas ============================
    # PAAS_SERVICE HOST/PORT

   
 location ~ ^/login/(.*) {
        proxy_pass http://OPEN_PAAS_LOGIN/$1$is_args$args;
        proxy_pass_header Server;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_redirect off;
        proxy_read_timeout 600;
    }
#user  root;
worker_processes  auto;

error_log  /usr/local/var/log/nginx/error.log;
#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    #default_type text/html;

    client_max_body_size 2G;
    server_names_hash_bucket_size 256;

    sendfile        on;

    keepalive_timeout  65;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' '$upstream_addr $upstream_response_time $request_time '; 
    access_log logs/access.log main;
    underscores_in_headers on;
    include /usr/local/etc/nginx/conf.d/*.conf;
}

 2.长连接需要配置

配置文件 proxy_set_header -发往后端服务器的请求头---- nginx日志设置级别调试技巧 - 长连接配置_nginx

 

 

 proxy_http_version 1.1;

proxy_set_header Connection "";  #如果没加,后端服务器会收到 Connection: close 的 Header,而不能复用连接; 清空connection的请求头,避免客户端传递短链接的请求头信息。

https://www.jianshu.com/p/fd16b3d10752

 

1.调试rewrite规则

调试rewrite规则时,如果规则写错只会看见一个404页面,可以在配置文件中开启nginx rewrite日志,进行调试。

server {
        error_log    /var/logs/nginx/example.com.error.log;
        rewrite_log on;
}

rewrite_log on; 开启后,它将发送所有的 rewrite 相关的日志信息到 error_log 文件中,使用 [notice] 级别。随后就可以在error_log 查看rewrite信息了。

2.使用location记录指定URL的日志

server {
        error_log    /var/logs/nginx/example.com.error.log;
        location /static/ { 
        error_log /var/logs/nginx/static-error.log debug; 
    }         
}

配置以上配置后,/static/ 相关的日志会被单独记录在static-error.log文件中。

nginx日志共三个参数
access_log: 定义日志的路径及格式。
log_format: 定义日志的模板。
open_log_file_cache: 定义日志文件缓存。

proxy_set_header X-Forwarded-For :如果后端Web服务器上的程序需要获取用户IP,从该Header头获取。proxy_set_header X-Forwarded-For $remote_addr;

用一个例子来演示会更加清晰



标签:set,http,log,配置文件,header,nginx,proxy,日志
From: https://blog.51cto.com/u_13747193/6552932

相关文章

  • Nginx 根据请求参数代理到指定网址
    1、参考nginx中将某一个请求的路径重定向到其它网址nginx:[emerg]unknowndirective"if($request_uri"in2、小坑if与($间需要有空格。判断请求路径中,是否包含/adminif($request_uri~'/admin'){return404;}3、配置location/xxxxx/client/register{......
  • flask中关于配置文件写法
    关于Flask中的配置文件有多种写法。一、通过from_object写入项目根目录下创建一个settings.py配置文件,代码如下classBaseConfig(object):DEBUG=TrueSECRET_KEY="fsdajklfjdsalk1654356"classProductionConfig(BaseConfig):DEBUG=Falseclass......
  • MacOs Docker nginx.conf 配置
    `server{listen8089;server_namelocalhost;client_max_body_size120M;#php容器项目地址root/var/www/html/shop;indexindex.phpindex.htmlindex.htm;location/{#try_files$uri$uri//index.php?s=$uri&$args;}......
  • 关于reset.css的一些思考与探究
    项目多了,大家多会有自己积累的一些reset.css的经历或者自己改进的代码,其实初衷还是很简单的,达到复用,重置浏览器的一些默认样式,实现跨浏览器兼容。 1、最早关注的还是YUI的ResetCSS,  在线的压缩版本地址:http://yui.yahooapis.com/3.4.1/build/cssreset/cssreset-min.css 直接上......
  • IDEA : Cannot Save Setting ** must not contain source root **. The root alrea
    今天突然碰到这个问题,具体原因是parant目录不能放src的code。解决方法图片右侧的父project的SoureceFolders,是不是把子模块module或者其他模块加载进来(会标红),删除即可......
  • macbook m1 使用 brew 安装 nginx + 多版本 php
    目录macbookm1使用brew安装nginx+多版本php安装多个php版本1.配置php仓库2.安装多版本php3.配置php-pfm的端口4.启动php-pfm服务5.切换php-cli命令行的版本安装nginxmacbookm1使用brew安装nginx+多版本php在FastAdmin开发是,可能会用到多个p......
  • 使用 Debian、Docker 和 Nginx 部署 Web 应用
    前言本文将介绍基于Debian的系统上使用Docker和Nginx进行Web应用部署的过程。着重介绍了Debian、Docker和Nginx的安装和配置。第1步:更新和升级Debian系统通过SSH连接到服务器。更新软件包列表:sudoaptupdate升级已安装的软件包:sudoaptupgrade第2步......
  • 服务器与本地资源同步,在ubuntu自建git库,使用nginx远程http访问
    xshell在linux与windows之间传文件虽然方便,但使用git才能真正实现资源同步。为实现服务器与本地资源同步,在ubuntu服务器端自建git库。使用 git-http-backend 搭建git服务的原理都是类似的,主要是利用web服务器(apache/nginx)进行用户认证,并将用户信息传递给CGI程序 ......
  • Nginx反向代理&记录用户IP地址企业案例
    反向代理机器节点:lb0110.0.0.30#lb01是反向代理服务器(包括负载均衡的功能)www0110.0.0.40www0210.0.0.50【演示反向代理功能】 图片解读:使用客户端机器www01,访问负载均衡lb01(反向代理),看到了www01,www02页面信息在www01服务器上检测客户端信息,发现请求是10.0.0.3......
  • 【mysql】parseTime=true 参数说明以及如何在 GORM 中使用它避免 Scan error on colum
    什么是parseTime=true参数parseTime=true是一个MySQL数据库连接参数,它告诉MySQL驱动程序将日期时间类型的值解析为time.Time类型。在MySQL中,日期时间类型的值可以表示为字符串,例如2022-07-0113:30:00。默认情况下,MySQL驱动程序将这些值作为[]uint8类型返回,这可能......