• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
没心情
Beauty begins the moment you decide to be yourself.
博客园    首页    新随笔    联系   管理    订阅  订阅
nginx配置文件详解加示例

user nobody;

worker_processes 1;

error_log logs/error.log;

error_log logs/error.log notice;

error_log logs/error.log info;

pid logs/nginx.pid;

events {
worker_connections 1024;
}

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

#这个是nginx日志的配置参数信息,根据配置,可以按照规格打印日志信息
log_format main escape=json '{ "@timestamp": "$time_iso8601", '
                   '"remote_addr": "$remote_addr",'
                   '"costime": "$request_time",'
                   '"realtime": "$upstream_response_time",'
                   '"status": $status,'
                   '"x_forwarded": "$http_x_forwarded_for",'
                   '"referer": "$http_referer",'
                   '"request": "$request",'
                   '"upstr_addr": "$upstream_addr",'
                   '"bytes":$body_bytes_sent,'
                   '"dm":$request_body,'
                   '"agent": "$http_user_agent" }';

#这是nginx保存日志的文件
access_log  logs/access.log  main;


#
client_header_buffer_size 10m;
large_client_header_buffers 4 10m;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {

	listen       9001;
    server_name  localhost;
	
	#转发代理服务地址
	location ~ /eduservice/	{
		proxy_pass http://localhost:8001;
		
	
	}
	
	location ~ /eduoss/	{
		proxy_pass http://localhost:8002;
	
	}
	
   

    #charset koi8-r;

    access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
		client_max_body_size 1000m;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
			

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

日志配置参数详解:
log_format log 格式 '配置规则';

日志格式设置:

$remote_addr与$http_x_forwarded_for用以记录客户端的ip地址;

$remote_user:用来记录客户端用户名称;

$time_local: 用来记录访问时间与时区;

$request: 用来记录请求的url与http协议;

$status: 用来记录请求状态;成功是200,

$body_bytes_sent :记录发送给客户端文件主体内容大小;

$http_referer:用来记录从那个页面链接访问过来的;

$http_user_agent:记录客户浏览器的相关信息

posted on 2021-01-19 09:58  No-心情  阅读(127)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3