一、配置

先来看看Nginx的日志格式

#grep -A2 log_format /usr/local/nginx/conf/nginx.conf

log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'

' $host "$request_uri" $status'

' "$http_referer" "$http_user_agent"';

//combined_realip为日志格式名字,$remote_addr为网站的用户的出口IP;

//$http_x_forwarded_for 为代理服务器的IP,如果使用了代理,则会记录IP

//$time_local为当前时间;$host为主机名;$request_uri为访问的URL地址

//$status为状态码,$http_referer为referer地址,$http_user_agent为user_agent

修改配置文件

#vi /usr/local/nginx/conf/vhost/test.com.conf

写入:

server

{

listen 80;

server_name test.com;

index index.html index.htm index.php;

root /data/nginx/test.com;

if ($host != 'test.com' ){

rewrite ^(.*)$ http://test.com/$1 permanent;

}

access_log /tmp/1.log combined_realip;

}

//使用access_log来指定日志的存储路径,最后面为日志的格式名字

#/usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

二、检验测试

#curl -x127.0.0.1:80 test.com/111 - I

状态码404

#cat /tmp/1.log

127.0.0.1

LNMP配置——Nginx配置 —— Nginx的访问日志的更多相关文章

  1. nginx定时备份access访问日志并重启nginx

    用.sh脚本写了备份日志脚本 其实就是转移文件改名后重新建一个空文件 mv /alidata/log/nginx/access/wxtest.log /alidata/log/nginx/access ...

  2. Nginx配置性能优化

    大多数的Nginx安装指南告诉你如下基础知识--通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了.而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...

  3. Nginx配置性能优化(转)

    大多数的Nginx安装指南告诉你如下基础知识——通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了.而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...

  4. nginx笔记 安装nginx 配置 反向代理 多虚拟主机

    1,检测linux上是否 通过yum安装了nginxrpm   -qi  nginx 2.安装nginx之前的依赖包yum install gcc patch libffi-devel python- ...

  5. 关于Nginx配置性能优化

    基本的 (优化过的)配置 将修改的唯一文件是nginx.conf,其中包含Nginx不同模块的所有设置.在服务器的/etc/nginx目录中找到nginx.conf. 首先,我们将谈论一些全局设置,然 ...

  6. Nginx配置优化详解

    如果你已经安装过Nginx并在生产环境中使用,那么Nginx配置优化你一定也要做,这样才能看到Nginx性能,本文就从基本配置优化开始到高层配置教你如何优化Nginx 大多数的Nginx安装指南告诉你 ...

  7. Nginx配置性能优化(转)

    原文地址:http://blog.csdn.net/xifeijian/article/details/20956605 高层的配置 nginx.conf文件中,Nginx中有少数的几个高级配置在模块 ...

  8. yum 安装nginx(配置开机启动)

    yum install -y nginx 通过yum安装的时候提示下面的错误 [root@localhost yum.repos.d]# yum install nginx 已加载插件:fastest ...

  9. [转] Nginx配置性能优化

    大多数的Nginx安装指南告诉你如下基础知识——通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了.而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...

  10. nginx配置详解---学校资料

    #配置worker进程运行用户 nobody也是一个linux用户,一般用于启动程序,没有密码 user nobody; #配置工作进程数目,根据硬件调整,通常等于CPU数量或者2倍于CPU数量 wo ...

随机推荐

  1. 记一次基于springboot+aop实现日志记录实战

    1. 为什么要记录日志 好处: a. 可以对一些重要功能进行记录,方便以后跟踪是谁操作此功能的. b. 在操作某些功能时可能会发生异常,但每次出现异常我们想定位日志都要去服务器查看我们的日志.有了日志 ...

  2. python程序配置守护进程

    参考博客 python Supervisor 使用与配置_a35155的博客-CSDN博客 Ubuntu系统下:apt-get install supervisor,通过这种方式安装后,自动设置为开机 ...

  3. Dcoker命令使用详解

    Docker语法说明 docker [OPTIONS] COMMAND [arg...] OPTIONS --config=~/.docker :指定本地客户端配置文件. -D, --debug :开 ...

  4. 逆元 exgcd 费马小定理 中国剩余定理的理解和证明

    一.除法取模逆元 如果我们要通过一个前面取过模的式子递推出其他要取模的式子,而递推式里又存在除法 那么一个很尴尬的事情出现了,假如a[i-1]=100%31=7 a[i]=(a[i-1]/2)%31 ...

  5. Stack Overflow Skill IQ Testing All In One

    Stack Overflow Skill IQ Testing All In One Pluralsight IQ | Stack Overflow https://www.pluralsight.c ...

  6. js location API All In One

    js location API All In One location "use strict"; /** * * @author xgqfrms * @license MIT * ...

  7. 如何禁用 Chrome Taps Group feature 💩

    如何禁用 Chrome Taps Group feature bug https://support.google.com/chrome/go/feedback_confirmation How to ...

  8. macOS warning emoji render bug

    macOS warning emoji render bug ️ macOS render bug Apple Color Emoji fonts install old version fonts ...

  9. nasm astrstr函数 x86

    xxx.asm: %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain export as ...

  10. 「NGK每日快讯」12.18日NGK公链第45期官方快讯!