服务器、中间件、CGI
参考链接:https://www.cnblogs.com/applelife/p/10496379.html
CGI:http://www.360doc.com/content/18/0327/17/51484742_740649523.shtml
CGI比较:https://www.jianshu.com/p/80e46a80fdbd%20%20
服务器
服务器指的是一个管理资源并为用户提供服务的计算机软件,通常分为文件服务器、数据库服务器和应用程序服务器。运行以上软件的计算机或计算机系统也被称为服务器。
中间件
中间件是服务器上负责解析http请求的一组应用程序,负责接收并解析http请求数据包,在服务器上找到数据包所请求的文件后,将其返回给客户端,如果http数据包所请求的是一个动态脚本文件,如php等,中间件就要靠CGI与脚本语言解析软件进行交互,处理好动态脚本文件后,再将处理后的文件其返回给浏览器。
说白了,中间件就是服务器上web端口(通常为80端口)的一个翻译官,负责告诉服务器用户要请求哪些文件,如果用户请求的是一个静态的html页面,就直接在服务器上找到对应文件并将其交给用户浏览器,如果用户请求的是一个动态页面如php,asp等,中间件在找到该文件后,将其交给对应的脚本语言解析程序,脚本语言解析程序将文件解析成html后,再把解析过的文件发送给浏览器。
所以,浏览器本身并不能渲染解析动态脚本文件,以php为例,浏览器解析的.php文件,实际上是经服务器php程序解析后的html文件。
再者,如果服务器上没有安装中间件,那么服务器就不能理解用户发来的http数据包是什么意思,当然也就无法对http请求包进行正确的响应。
CGI 通用网关接口
早期的Web服务器,只能响应浏览器发来的HTTP静态资源的请求,并将存储在服务器中的静态资源返回给浏览器。随着Web技术的发展,逐渐出现了动态技术,但是Web服务器并不能够直接运行动态脚本,为了解决Web服务器与外部应用程序之间数据互通,于是出现了CGI(Common Gateway Interface)通用网关接口。简单理解,可以认为CGI是Web服务器和运行其上的应用程序进行“交流”的一种约定。
(随着网站越来越复杂,出现动态技术。但是服务器并不能直接运行 php,asp这样的文件,自己不能做,外包给别人吧,但是要与第三做个约定,我给你什么,然后你给我什么,就是我把请求参数发送给你,然后我接收你的处理结果给客户端。那这个约定就是 common gateway interface,简称cgi。cgi只是接口协议)
CGI是Web服务器和一个独立的进程之间的协议,它会把HTTP请求Request的Header头设置成进程的环境变量,HTTP请求的Body正文设置成进程的标准输入,进程的标准输出设置为HTTP响应Response,包含Header头和Body正文。
以php为例:
CGI就像翻译机,将PHP语言给服务器解释,便于相互之间的理解和通讯,最后呈现给浏览器。
请求动态资源的模型
服务器和客户端之间的通信,是客户端的浏览器和服务器端的http服务器之间的HTTP通信。
服务器和CGI程序之间是通过标准输入输出来进行数据传递的,而这个过程需要环境变量的协作方可实现。
在了解完基础的中间件、服务器、CGI知识之后,就能明确知道接下来的日志如何去查看了,因为可能会出现apache + tomcat 的部署关系,或者 nginx + tomcat。
总结:
有tomcat就看tomcat日志
无tomcat 就查看 nginx、apache。
中间件日志
IIS
IIS是一种Web(网页)服务组件,其中包括Web服务器、FTP服务器、NNTP服务器和SMTP服务器,分别用于网页浏览、文件传输、新闻服务和邮件发送等方面,它使得在网络(包括互联网和局域网)上发布信息成了一件很容易的事。
日志配置
日志存储路径:

access.log
以下是一段访问日志
#Software: Microsoft Internet Information Services 7.5#Version: 1.0#Date: 2021-03-29 07:35:48#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken2021-03-29 07:35:48 172.16.50.134 GET / - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64;+rv:87.0)+Gecko/20100101+Firefox/87.0 200 0 0 9512021-03-29 07:35:48 172.16.50.134 GET /welcome.png - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64;+rv:87.0)+Gecko/20100101+Firefox/87.0 200 0 0 152021-03-29 07:35:48 172.16.50.134 GET /favicon.ico - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64;+rv:87.0)+Gecko/20100101+Firefox/87.0 404 0 2 462021-03-29 07:38:33 172.16.50.134 GET / - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 200 0 0 152021-03-29 07:38:33 172.16.50.134 GET /izza2hd01sGE - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /87mA4jXxKqAc - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /GEgvVZIVMtIN/ - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /T9pjKFYb2FRq/ - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /.gXVRIOICCQ1z - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /.jaF9yfMPGql5 - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /wTSnz2iF7rrq.* - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /XyBAhd1HyxUB.* - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 152021-03-29 07:38:33 172.16.50.134 GET /+../ - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /!.htpasswd - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 02021-03-29 07:38:33 172.16.50.134 GET /*.bak - 80 - 172.16.10.121 Mozilla/5.0+(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/28.0.1468.0+Safari/537.36 404 0 2 0
Apache
Apache HTTP服务器是一个模块化的服务器,可以运行在几乎所有广泛使用的计算机平台上。其属于应用服务器。Apache支持支持模块多,性能稳定,Apache本身是静态解析,适合静态HTML、图片等,但可以通过扩展脚本、模块等支持动态页面等。
(Apche可以支持PHPCGIPerl,但是要使用Java的话,你需要Tomcat在Apache后台支撑,将Java请求由Apache转发给Tomcat处理。) 缺点:配置相对复杂,自身不支持动态页面。
Apache日志详解
Apache日志文件名称及路径介绍
当我们安装并启动Apache后,Apache会自动生成两个日志文件,这两个日志文件分别是访问日志access_log(在Windows上是access.log)和错误日志error_log(在Windows上是error.log)。如果使用 SSL 服务的话,还可能存在 ssl_access_log和ssl_error_log 和 ssl_request_log 三种日志文件。
日志文件的路径根据安装方式不同位置也是不一样的,一般都是在Apache安装目录的logs子目录中,日志文件路径可根据实际安装情况在Apache的配置文件中进行查找。
Windows:
Linux: /usr/local/apache/logs/access_log | error_log
https://blog.51cto.com/longlei/2095594
https://blog.csdn.net/u013699800/article/details/37593491
http://httpd.apache.org/docs/2.4/mod/mod_log_config.html#customlog
配置文件
配置文件路径
在apahce的配置文件中,可以定制详细的日志文件格式:
很久以前,日志文件只有一种格式,这就是“公共格式”,许多人已经习惯于使用这种格式。随后出现了定制日志格式,而且看起来定制日志格式更很受欢迎,即使公共日志格式本身也重新用定制日志格式定义。
定制日志文件的格式涉及到两个指令,即LogFormat指令和CustomLog指令。 默认httpd.conf文件提供了关于这两个指令的几个示例。
LogFormat指令:定义格式并为格式指定一个名字,以后我们就可以直接引用这个名字。
CustomLog指令:设置日志文件,并指明日志文件所用的格式(通常通过格式的名字)。
截取关键部分:(重点 6、7、27行)
<IfModule log_config_module>## The following directives define some format nicknames for use with# a CustomLog directive (see below).#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" common<IfModule logio_module># You need to enable mod_logio.c to use %I and %OLogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio</IfModule>## The location and format of the access logfile (Common Logfile Format).# If you do not define any access logfiles within a <VirtualHost># container, they will be logged here. Contrariwise, if you *do*# define per-<VirtualHost> access logfiles, transactions will be# logged therein and *not* in this file.##CustomLog "logs/access_log" common## If you prefer a logfile with access, agent, and referer information# (Combined Logfile Format) you can use the following directive.#CustomLog "logs/access_log" combined</IfModule>
- %a: 远程IP地址
- %A: 本地IP地址
- %B: 已发送的字节数,不包含HTTP头
- %b: CLF格式的已发送字节数量,不包含HTTP头。例如当没有发送数据时,写入‘-’而不是0。
- %{FOOBAR}e: 环境变量FOOBAR的内容
- %f: 文件名字
- %h: 远程主机
- %H 请求的协议
- %Foobar}i: Foobar的内容,发送给服务器的请求的标头行。
- %l: 远程登录名字(来自identd,如提供的话)
- %m: 请求的方法
- %{Foobar}n: 来自另外一个模块的注解“Foobar”的内容
- %{Foobar}o: Foobar的内容,应答的标头行
- %p: 服务器响应请求时使用的端口
- %P: 响应请求的子进程ID。
- %q: 查询字符串(如果存在查询字符串,则包含“?”后面的部分;否则,它是一个空字符串。)
- %r: 请求的第一行
- %s: 状态。对于进行内部重定向的请求,这是指原来请求的状态。如果用%…>s,则是指后来的请求。
- %t: 以公共日志时间格式表示的时间(或称为标准英文格式)
- %{format}t: 以指定格式format表示的时间
- %T: 为响应请求而耗费的时间,以秒计
- %u: 远程用户(来自auth;如果返回状态(%s)是401则可能是伪造的)
- %U: 用户所请求的URL路径
- %v: 响应请求的服务器的ServerName
- %V: 依照UseCanonicalName设置得到的服务器名字
完整的日志文件:
## This is the main Apache HTTP server configuration file. It contains the# configuration directives that give the server its instructions.# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.# In particular, see# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html># for a discussion of each configuration directive.## Do NOT simply read the instructions in here without understanding# what they do. They're here only as hints or reminders. If you are unsure# consult the online docs. You have been warned.## Configuration and logfile names: If the filenames you specify for many# of the server's control files begin with "/" (or "drive:/" for Win32), the# server will use that explicit path. If the filenames do *not* begin# with "/", the value of ServerRoot is prepended -- so 'log/access_log'# with ServerRoot set to '/www' will be interpreted by the# server as '/www/log/access_log', where as '/log/access_log' will be# interpreted as '/log/access_log'.## ServerRoot: The top of the directory tree under which the server's# configuration, error, and log files are kept.## Do not add a slash at the end of the directory path. If you point# ServerRoot at a non-local disk, be sure to specify a local disk on the# Mutex directive, if file-based mutexes are used. If you wish to share the# same ServerRoot for multiple httpd daemons, you will need to change at# least PidFile.#ServerRoot "/etc/httpd"## Listen: Allows you to bind Apache to specific IP addresses and/or# ports, instead of the default. See also the <VirtualHost># directive.## Change this to Listen on specific IP addresses as shown below to# prevent Apache from glomming onto all bound IP addresses.##Listen 12.34.56.78:80Listen 80## Dynamic Shared Object (DSO) Support## To be able to use the functionality of a module which was built as a DSO you# have to place corresponding `LoadModule' lines at this location so the# directives contained in it are actually available _before_ they are used.# Statically compiled modules (those listed by `httpd -l') do not need# to be loaded here.## Example:# LoadModule foo_module modules/mod_foo.so#Include conf.modules.d/*.conf## If you wish httpd to run as a different user or group, you must run# httpd as root initially and it will switch.## User/Group: The name (or #number) of the user/group to run httpd as.# It is usually good practice to create a dedicated user and group for# running httpd, as with most system services.#User apacheGroup apache# 'Main' server configuration## The directives in this section set up the values used by the 'main'# server, which responds to any requests that aren't handled by a# <VirtualHost> definition. These values also provide defaults for# any <VirtualHost> containers you may define later in the file.## All of these directives may appear inside <VirtualHost> containers,# in which case these default settings will be overridden for the# virtual host being defined.### ServerAdmin: Your address, where problems with the server should be# e-mailed. This address appears on some server-generated pages, such# as error documents. e.g. admin@your-domain.com#ServerAdmin root@localhost## ServerName gives the name and port that the server uses to identify itself.# This can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## If your host doesn't have a registered DNS name, enter its IP address here.##ServerName www.example.com:80## Deny access to the entirety of your server's filesystem. You must# explicitly permit access to web content directories in other# <Directory> blocks below.#<Directory />AllowOverride noneRequire all denied</Directory>## Note that from this point forward you must specifically allow# particular features to be enabled - so if something's not working as# you might expect, make sure that you have specifically enabled it# below.### DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.#DocumentRoot "/var/www/html"## Relax access to content within /var/www.#<Directory "/var/www">AllowOverride None# Allow open access:Require all granted</Directory># Further relax access to the default document root:<Directory "/var/www/html">## Possible values for the Options directive are "None", "All",# or any combination of:# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All"# doesn't give it to you.## The Options directive is both complicated and important. Please see# http://httpd.apache.org/docs/2.4/mod/core.html#options# for more information.#Options Indexes FollowSymLinks## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:# Options FileInfo AuthConfig Limit#AllowOverride None## Controls who can get stuff from this server.#Require all granted</Directory>## DirectoryIndex: sets the file that Apache will serve if a directory# is requested.#<IfModule dir_module>DirectoryIndex index.html</IfModule>## The following lines prevent .htaccess and .htpasswd files from being# viewed by Web clients.#<Files ".ht*">Require all denied</Files>## ErrorLog: The location of the error log file.# If you do not specify an ErrorLog directive within a <VirtualHost># container, error messages relating to that virtual host will be# logged here. If you *do* define an error logfile for a <VirtualHost># container, that host's errors will be logged there and not here.#ErrorLog "logs/error_log"## LogLevel: Control the number of messages logged to the error_log.# Possible values include: debug, info, notice, warn, error, crit,# alert, emerg.#LogLevel warn<IfModule log_config_module>## The following directives define some format nicknames for use with# a CustomLog directive (see below).#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" common<IfModule logio_module># You need to enable mod_logio.c to use %I and %OLogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio</IfModule>## The location and format of the access logfile (Common Logfile Format).# If you do not define any access logfiles within a <VirtualHost># container, they will be logged here. Contrariwise, if you *do*# define per-<VirtualHost> access logfiles, transactions will be# logged therein and *not* in this file.##CustomLog "logs/access_log" common## If you prefer a logfile with access, agent, and referer information# (Combined Logfile Format) you can use the following directive.#CustomLog "logs/access_log" combined</IfModule><IfModule alias_module>## Redirect: Allows you to tell clients about documents that used to# exist in your server's namespace, but do not anymore. The client# will make a new request for the document at its new location.# Example:# Redirect permanent /foo http://www.example.com/bar## Alias: Maps web paths into filesystem paths and is used to# access content that does not live under the DocumentRoot.# Example:# Alias /webpath /full/filesystem/path## If you include a trailing / on /webpath then the server will# require it to be present in the URL. You will also likely# need to provide a <Directory> section to allow access to# the filesystem path.## ScriptAlias: This controls which directories contain server scripts.# ScriptAliases are essentially the same as Aliases, except that# documents in the target directory are treated as applications and# run by the server when requested rather than as documents sent to the# client. The same rules about trailing "/" apply to ScriptAlias# directives as to Alias.#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"</IfModule>## "/var/www/cgi-bin" should be changed to whatever your ScriptAliased# CGI directory exists, if you have that configured.#<Directory "/var/www/cgi-bin">AllowOverride NoneOptions NoneRequire all granted</Directory><IfModule mime_module>## TypesConfig points to the file containing the list of mappings from# filename extension to MIME-type.#TypesConfig /etc/mime.types## AddType allows you to add to or override the MIME configuration# file specified in TypesConfig for specific file types.##AddType application/x-gzip .tgz## AddEncoding allows you to have certain browsers uncompress# information on the fly. Note: Not all browsers support this.##AddEncoding x-compress .Z#AddEncoding x-gzip .gz .tgz## If the AddEncoding directives above are commented-out, then you# probably should define those extensions to indicate media types:#AddType application/x-compress .ZAddType application/x-gzip .gz .tgz## AddHandler allows you to map certain file extensions to "handlers":# actions unrelated to filetype. These can be either built into the server# or added with the Action directive (see below)## To use CGI scripts outside of ScriptAliased directories:# (You will also need to add "ExecCGI" to the "Options" directive.)##AddHandler cgi-script .cgi# For type maps (negotiated resources):#AddHandler type-map var## Filters allow you to process content before it is sent to the client.## To parse .shtml files for server-side includes (SSI):# (You will also need to add "Includes" to the "Options" directive.)#AddType text/html .shtmlAddOutputFilter INCLUDES .shtml</IfModule>## Specify a default charset for all content served; this enables# interpretation of all content as UTF-8 by default. To use the# default browser choice (ISO-8859-1), or to allow the META tags# in HTML content to override this choice, comment out this# directive:#AddDefaultCharset UTF-8<IfModule mime_magic_module>## The mod_mime_magic module allows the server to use various hints from the# contents of the file itself to determine its type. The MIMEMagicFile# directive tells the module where the hint definitions are located.#MIMEMagicFile conf/magic</IfModule>## Customizable error responses come in three flavors:# 1) plain text 2) local redirects 3) external redirects## Some examples:#ErrorDocument 500 "The server made a boo boo."#ErrorDocument 404 /missing.html#ErrorDocument 404 "/cgi-bin/missing_handler.pl"#ErrorDocument 402 http://www.example.com/subscription_info.html### EnableMMAP and EnableSendfile: On systems that support it,# memory-mapping or the sendfile syscall may be used to deliver# files. This usually improves server performance, but must# be turned off when serving from networked-mounted# filesystems or if support for these functions is otherwise# broken on your system.# Defaults if commented: EnableMMAP On, EnableSendfile Off##EnableMMAP offEnableSendfile on# Supplemental configuration## Load config files in the "/etc/httpd/conf.d" directory, if any.IncludeOptional conf.d/*.conf
access_log
格式:
1.远程主机IP 2.空白(E-mail) 3.空白(登录名) 4.请求时间 5.方法、资源、协议 6.响应码 7.发送字节 8.referer 9.UA
这一些内容都是配置文件中决定的
[root@localhost httpd]# head -n 100 access_log-20210328172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET / HTTP/1.1" 403 4897 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /noindex/css/bootstrap.min.css HTTP/1.1" 200 19341 "http://172.16.50.185/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /noindex/css/open-sans.css HTTP/1.1" 200 5081 "http://172.16.50.185/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /images/apache_pb.gif HTTP/1.1" 200 2326 "http://172.16.50.185/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /images/poweredby.png HTTP/1.1" 200 3956 "http://172.16.50.185/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /noindex/css/fonts/Bold/OpenSans-Bold.woff HTTP/1.1" 404 239 "http://172.16.50.185/noindex/css/open-sans.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /noindex/css/fonts/Light/OpenSans-Light.woff HTTP/1.1" 404 241 "http://172.16.50.185/noindex/css/open-sans.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://172.16.50.185/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /noindex/css/fonts/Bold/OpenSans-Bold.ttf HTTP/1.1" 404 238 "http://172.16.50.185/noindex/css/open-sans.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:24 +0800] "GET /noindex/css/fonts/Light/OpenSans-Light.ttf HTTP/1.1" 404 240 "http://172.16.50.185/noindex/css/open-sans.css" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:28 +0800] "GET /sqli-labs/ HTTP/1.1" 200 7933 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:28 +0800] "GET /sqli-labs/index.html_files/freemind2html.css HTTP/1.1" 200 1335 "http://172.16.50.185/sqli-labs/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:28 +0800] "GET /sqli-labs/index.html_files/freemind2html.js HTTP/1.1" 404 241 "http://172.16.50.185/sqli-labs/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:28 +0800] "GET /sqli-labs/index.html_files/image.png HTTP/1.1" 200 81003 "http://172.16.50.185/sqli-labs/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:43 +0800] "GET /sqli-labs/Less-8 HTTP/1.1" 301 246 "http://172.16.50.185/sqli-labs/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:43 +0800] "GET /sqli-labs/Less-8/ HTTP/1.1" 200 694 "http://172.16.50.185/sqli-labs/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:43 +0800] "GET /sqli-labs/images/Less-8.jpg HTTP/1.1" 200 24369 "http://172.16.50.185/sqli-labs/Less-8/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:48 +0800] "GET /sqli-labs/Less-8/?id=1 HTTP/1.1" 200 706 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:24:55 +0800] "GET /sqli-labs/Less-8/?id=1%27 HTTP/1.1" 200 722 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"172.16.10.121 - - [25/Mar/2021:12:25:04 +0800] "GET /sqli-labs/Less-8/?id=1 HTTP/1.1" 200 706 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
Nginx
Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的。从2004年发布至今,凭借开源的力量,已经接近成熟与完善。
Nginx功能丰富,可作为HTTP服务器,也可作为反向代理服务器,邮件服务器。支持FastCGI、SSL、Virtual Host、URL Rewrite、Gzip等功能。并且支持很多第三方的模块扩展。
配置文件

conf文件夹的nginx.conf文件,Nginx服务器的基础配置,默认的配置也存放在此。
在 nginx.conf 的注释符号为: #
默认的 nginx 配置文件 nginx.conf 内容如下:
#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;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#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;# }#}}
nginx 文件结构
... #全局块events { #events块...}http #http块{... #http全局块server #server块{... #server全局块location [PATTERN] #location块{...}location [PATTERN]{...}}server{...}... #http全局块}
- 1、全局块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。
- 2、events块:配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。
- 3、http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。
- 4、server块:配置虚拟主机的相关参数,一个http中可以有多个server。
- 5、location块:配置请求的路由,以及各种页面的处理情况。
可以参照这个配置文件,注意绿色的那一部分,也就是日志内容
########### 每个指令必须有分号结束。##################user administrator administrators; #配置用户或者组,默认为nobody nobody。#worker_processes 2; #允许生成的进程数,默认为1#pid /nginx/pid/nginx.pid; #指定nginx进程运行文件存放地址error_log log/error.log debug; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emergevents {accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为onmulti_accept on; #设置一个进程是否同时接受多个网络连接,默认为off#use epoll; #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventportworker_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; #拒绝的ipallow 172.18.5.54; #允许的ip}}}
- 1.$remote_addr 与 $http_x_forwarded_for 用以记录客户端的ip地址;
- 2.$remote_user :用来记录客户端用户名称;
- 3.$time_local : 用来记录访问时间与时区;
- 4.$request : 用来记录请求的url与http协议;
- 5.$status : 用来记录请求状态;成功是200;
- 6.$body_bytes_s ent :记录发送给客户端文件主体内容大小;
- 7.$http_referer :用来记录从那个页面链接访问过来的;
- 8.$http_user_agent :记录客户端浏览器的相关信息;
日志文件
Nginx日志主要分为两种:access_log(访问日志)和error_log(错误日志)。通过访问日志我们可以得到用户的IP地址、浏览器的信息,请求的处理时间等信息。错误日志记录了访问出错的信息,可以帮助我们定位错误的原因。nginx的日志不会自动分割。
access_log
路径参照配置文件就可以找到,日志的详细内容需要参考nginx.conf中的配置文件
例如我本地配置为:
log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log logs/access.log main;
远程地址 用户 时间 请求方法 状态码 发送的字节 referer ua xff
10.11.243.33 - - [05/Jan/2021:17:07:27 +0800] "GET / HTTP/1.1" 200 1214 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" "-"10.11.243.33 - - [05/Jan/2021:17:07:33 +0800] "GET /favicon.ico HTTP/1.1" 404 711 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" "-"10.11.243.33 - - [05/Jan/2021:17:07:36 +0800] "GET / HTTP/1.1" 200 1214 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0" "-"10.11.241.10 - - [12/Jan/2021:17:59:32 +0800] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:52:25 +0800] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:54:50 +0800] "GET / HTTP/1.1" 499 0 "-" "Mozilla/4.75 [en] (X11, U; Scanner)" "-"10.11.241.10 - - [12/Jan/2021:18:55:00 +0800] "GET /en-US/account/login HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:55:27 +0800] "GET /portal/ HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:55:58 +0800] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:56:44 +0800] "GET /server_version.xsl HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:58:26 +0800] "GET /_profiler/latest HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:58:37 +0800] "GET /web/app_dev.php/_configurator/step/0 HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:18:58:46 +0800] "GET /app.php HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:19:02:55 +0800] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:19:02:58 +0800] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [12/Jan/2021:19:16:56 +0800] "GET http://www.openvas.org/openvas-proxy-test HTTP/1.1" 499 0 "-" "Mozilla/5.0 [en] (X11, U; Scanner )" "-"10.11.241.10 - - [13/Jan/2021:16:28:58 +0800] "GET / HTTP/1.1" 504 494 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" "-"10.11.241.10 - - [13/Jan/2021:16:29:24 +0800] "GET /favicon.ico HTTP/1.1" 499 0 "http://10.11.242.34:8000/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" "-"10.11.242.36 - - [13/Jan/2021:16:33:45 +0800] "HEAD / HTTP/1.1" 502 0 "-" "curl/7.29.0" "-"10.11.241.10 - - [13/Jan/2021:16:34:04 +0800] "GET / HTTP/1.1" 504 494 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" "-"10.11.241.10 - - [13/Jan/2021:16:35:04 +0800] "GET /favicon.ico HTTP/1.1" 502 494 "http://10.11.242.34:8000/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" "-"
error_log
错误日志主要记录客户端访问Nginx出错时的日志,格式不支持自定义。通过错误日志,你可以得到系统某个服务或server的性能瓶颈等。
[root@localhost logs]# head -n 100 error.log2021/01/05 14:20:00 [emerg] 11437#0: duplicate location "/" in /asap/nginx/conf/domains/8000.conf:142021/01/05 14:21:06 [emerg] 11441#0: duplicate location "/" in /asap/nginx/conf/domains/8000.conf:142021/01/05 14:23:36 [notice] 11465#0: signal process started2021/01/05 14:26:01 [emerg] 11526#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:26:01 [emerg] 11526#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:26:01 [emerg] 11526#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:26:01 [emerg] 11526#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:26:01 [emerg] 11526#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:26:01 [emerg] 11526#0: still could not bind()2021/01/05 14:27:01 [emerg] 11548#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:27:01 [emerg] 11548#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:27:01 [emerg] 11548#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:27:01 [emerg] 11548#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)2021/01/05 14:27:01 [emerg] 11548#0: bind() to 0.0.0.0:8000 failed (98: Address already in use)
Tomcat
参考链接:https://www.cnblogs.com/operationhome/p/9680040.html
Tomcat 对应日志的配置文件:tomcat目录下的/conf/logging.properties。
Tomcat 的日志等级有:日志输出级别:SEVERE (最高级别) > WARNING > INFO > CONFIG > FINE > FINER(精心) > FINEST (所有内容,最低级别)
使用日志输出级别越高那么tomcat对内存的消耗就越低
Tomcat 有五类日志 :catalina、localhost、manager、admin、host-manager
/conf/logging.properties 配置文件:
# Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements. See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You under the Apache License, Version 2.0# (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#可配置项(5类日志):catalina、localhost、manager、admin、host-managerhandlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler#日志输出为输出到文件和输出到控制台.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler############################################################# Handler specific properties.# Describes specific configuration info for Handlers.#############################################################日志输出级别:SEVERE (最高级别) > WARNING > INFO > CONFIG > FINE > FINER(精心) > FINEST (所有内容,最低级别)#配置文件使catalina日志输出级别为FINE1catalina.org.apache.juli.AsyncFileHandler.level = FINE#catalina文件输出位置1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs#catalina日志前缀为catalina1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-82localhost.org.apache.juli.AsyncFileHandler.level = FINE2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-83manager.org.apache.juli.AsyncFileHandler.level = FINE3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs3manager.org.apache.juli.AsyncFileHandler.prefix = manager.3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-84host-manager.org.apache.juli.AsyncFileHandler.level = FINE4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8#配置文件使控制台日志输出级别为FINEjava.util.logging.ConsoleHandler.level = FINEjava.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatterjava.util.logging.ConsoleHandler.encoding = UTF-8############################################################# Facility specific properties.# Provides extra control for each logger.#############################################################localhost日志文件输出级别为INFOorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFOorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandlerorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFOorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandlerorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFOorg.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler# For example, set the org.apache.catalina.util.LifecycleBase logger to log# each component that extends LifecycleBase changing state:#org.apache.catalina.util.LifecycleBase.level = FINE# To see debug messages in TldLocationsCache, uncomment the following line:#org.apache.jasper.compiler.TldLocationsCache.level = FINE# To see debug messages for HTTP/2 handling, uncomment the following line:#org.apache.coyote.http2.level = FINE# To see debug messages for WebSocket handling, uncomment the following line:#org.apache.tomcat.websocket.level = FINE
日志文件详解
catalina.out
即标准输出和标准出错,所有输出到这两个位置的都会进入catalina.out,这里包含tomcat运行自己输出的日志以及应用里向console输出的日志。默认这个日志文件是不会进行自动切割的,我们需要借助其他工具进行切割(注意:catalina.out文件如果过大会影响)
截取的部分日志内容
[root@localhost logs]# head -n 100 catalina.out28-Dec-2020 18:07:49.782 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/8.5.6128-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建: Dec 3 2020 14:03:28 UTC28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号: 8.5.61.028-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称: Linux28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 3.10.0-693.el7.x86_6428-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 架构: amd6428-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: /usr/java/jdk1.8.0_271-amd64/jre28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java虚拟机版本: 1.8.0_271-b0928-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.5.61/conf/logging.properties28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djdk.tls.ephemeralDHKeySize=204828-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dorg.apache.catalina.security.SecurityListener.UMASK=002728-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dignore.endorsed.dirs=28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.base=/usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.home=/usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.io.tmpdir=/usr/local/apache-tomcat-8.5.61/temp28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 在java.library.path:[/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]上找不到基于APR的Apache Tomcat本机库,该库允许在生产环境中获得最佳性能28-Dec-2020 18:07:49.883 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["http-nio-8080"]28-Dec-2020 18:07:49.893 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read28-Dec-2020 18:07:49.901 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 476 ms28-Dec-2020 18:07:49.919 信息 [main] org.apache.catalina.core.StandardService.startInternal 正在启动服务[Catalina]28-Dec-2020 18:07:49.919 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.6128-Dec-2020 18:07:49.929 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/ROOT]28-Dec-2020 18:07:50.099 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/ROOT]的部署已在[169]毫秒内完成28-Dec-2020 18:07:50.099 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/docs]28-Dec-2020 18:07:50.110 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/docs]的部署已在[11]毫秒内完成28-Dec-2020 18:07:50.110 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/examples]28-Dec-2020 18:07:50.249 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/examples]的部署已在[139]毫秒内完成28-Dec-2020 18:07:50.250 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/host-manager]28-Dec-2020 18:07:50.264 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/host-manager]的部署已在[14]毫秒内完成28-Dec-2020 18:07:50.265 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/manager]28-Dec-2020 18:07:50.276 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/manager]的部署已在[11]毫秒内完成28-Dec-2020 18:07:50.279 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-8080"]
catalina.YYYY-MM-DD.log
catalina.{yyyy-MM-dd}.log是tomcat自己运行的一些日志,这些日志还会输出到catalina.out,但是应用向console输出的日志不会输出到catalina.{yyyy-MM-dd}.log,它是tomcat的启动和暂停时的运行日志,注意,它和catalina.out是里面的内容是不一样的。
对比两段日志可以看到 tomcat自己运行的日志分别输出到 catalina.out 与catalina.2020-12-28.log中。
[root@localhost logs]# head -n 100 catalina.2020-12-28.log28-Dec-2020 18:07:49.782 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/8.5.6128-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建: Dec 3 2020 14:03:28 UTC28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号: 8.5.61.028-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称: Linux28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 3.10.0-693.el7.x86_6428-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 架构: amd6428-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: /usr/java/jdk1.8.0_271-amd64/jre28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java虚拟机版本: 1.8.0_271-b0928-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation28-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.785 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.5.61/conf/logging.properties28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djdk.tls.ephemeralDHKeySize=204828-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dorg.apache.catalina.security.SecurityListener.UMASK=002728-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dignore.endorsed.dirs=28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.base=/usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Dcatalina.home=/usr/local/apache-tomcat-8.5.6128-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数: -Djava.io.tmpdir=/usr/local/apache-tomcat-8.5.61/temp28-Dec-2020 18:07:49.786 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 在java.library.path:[/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]上找不到基于APR的Apache Tomcat本机库,该库允许在生产环境中获得最佳性能28-Dec-2020 18:07:49.883 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["http-nio-8080"]28-Dec-2020 18:07:49.893 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read28-Dec-2020 18:07:49.901 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 476 ms28-Dec-2020 18:07:49.919 信息 [main] org.apache.catalina.core.StandardService.startInternal 正在启动服务[Catalina]28-Dec-2020 18:07:49.919 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.6128-Dec-2020 18:07:49.929 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/ROOT]28-Dec-2020 18:07:50.099 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/ROOT]的部署已在[169]毫秒内完成28-Dec-2020 18:07:50.099 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/docs]28-Dec-2020 18:07:50.110 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/docs]的部署已在[11]毫秒内完成28-Dec-2020 18:07:50.110 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/examples]28-Dec-2020 18:07:50.249 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/examples]的部署已在[139]毫秒内完成28-Dec-2020 18:07:50.250 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/host-manager]28-Dec-2020 18:07:50.264 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/host-manager]的部署已在[14]毫秒内完成28-Dec-2020 18:07:50.265 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/manager]28-Dec-2020 18:07:50.276 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[/usr/local/apache-tomcat-8.5.61/webapps/manager]的部署已在[11]毫秒内完成28-Dec-2020 18:07:50.279 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-8080"]28-Dec-2020 18:07:50.290 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 388 ms28-Dec-2020 18:19:00.479 信息 [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [/usr/local/apache-tomcat-8.5.61/webapps/netBank]28-Dec-2020 18:19:01.288 信息 [localhost-startStop-2] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。28-Dec-2020 18:19:01.307 信息 [localhost-startStop-2] org.springframework.web.context.ContextLoader.initWebApplicationContext Root WebApplicationContext: initialization started28-Dec-2020 18:19:01.351 信息 [localhost-startStop-2] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing Root WebApplicationContext: startup date [Mon Dec 28 18:19:01 CST 2020]; root of context hierarchy28-Dec-2020 18:19:01.380 信息 [localhost-startStop-2] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from class path resource [applicationContext.xml]28-Dec-2020 18:19:01.573 信息 [localhost-startStop-2] org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2ee80376: defining beans [dataSource,sessionFactory,userDao,userService,user,admin,personinfoDao,personinfoService,personinfo,transactionDao,transactionService,transaction,transactionManager,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy28-Dec-2020 18:19:01.692 INFO [localhost-startStop-2] org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit> HCANN000001: Hibernate Commons Annotations {4.0.5.Final}28-Dec-2020 18:19:01.697 INFO [localhost-startStop-2] org.hibernate.Version.logVersion HHH000412: Hibernate Core {4.2.2.Final}28-Dec-2020 18:19:01.698 INFO [localhost-startStop-2] org.hibernate.cfg.Environment.<clinit> HHH000206: hibernate.properties not found28-Dec-2020 18:19:01.700 INFO [localhost-startStop-2] org.hibernate.cfg.Environment.buildBytecodeProvider HHH000021: Bytecode provider name : javassist28-Dec-2020 18:19:01.727 WARN [localhost-startStop-2] org.hibernate.internal.util.xml.DTDEntityResolver.resolveEntity HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
localhost.YYYY-MM-DD.log
localhost.{yyyy-MM-dd}.log主要是应用初始化(listener, filter, servlet)未处理的异常最后被tomcat捕获而输出的日志,它也是包含tomcat的启动和暂停时的运行日志,但它没有catalina.2020-12-28.log 日志全。它只是记录了部分日志。
[root@localhost logs]# head -n 100 localhost.2020-12-28.log28-Dec-2020 18:07:50.243 信息 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()28-Dec-2020 18:07:50.243 信息 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()28-Dec-2020 18:07:50.244 信息 [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: attributeAdded('StockTicker', 'async.Stockticker@17784821')28-Dec-2020 18:19:01.289 信息 [localhost-startStop-2] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath28-Dec-2020 18:19:01.307 信息 [localhost-startStop-2] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext28-Dec-2020 18:20:45.565 信息 [localhost-startStop-5] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath28-Dec-2020 18:20:51.421 信息 [localhost-startStop-5] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext28-Dec-2020 18:20:56.474 信息 [localhost-startStop-5] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'backendDispatcherServlet'28-Dec-2020 18:22:22.737 信息 [http-nio-8080-exec-4] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'dispatcherServlet'28-Dec-2020 18:27:35.557 严重 [http-nio-8080-exec-17] org.apache.catalina.core.StandardWrapperValve.invoke 在路径为/TomExam的上下文中,Servlet[jsp]的Servlet.service()引发了具有根本原因的异常无法为JSP编译类:在生成的java文件中的第:[16]行发生错误:[/usr/local/apache-tomcat-8.5.61/work/Catalina/localhost/TomExam/org/apache/jsp/WebRoot/login_jsp.java]Only a type can be imported. com.tom.cache.ConfigCache resolves to a packageJSP文件:[/WebRoot/login.jsp] 的第 [6] 行发生了一个错误ConfigCache cannot be resolved3: <html xmlns="http://www.w3.org/1999/xhtml">4: <head>5: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />6: <title><%=ConfigCache.getConfigByKey("sys_sitename") %> - 系统登陆</title>
localhost_access_log.YYYY-MM-DD.txt
localhost_access_log.2018-09-19.txt:这个是访问tomcat的日志,请求时间和资源,状态码都有记录。
溯源的时候,如果找到了时间切入点,则可以根据这个日志来进行溯源。
[root@localhost logs]# head -n 100 localhost_access_log.2020-12-28.txt127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET / HTTP/1.1" 200 11156127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET /tomcat.svg HTTP/1.1" 200 67795127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET /tomcat.css HTTP/1.1" 200 5542127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET /bg-nav.png HTTP/1.1" 200 1401127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET /asf-logo-wide.svg HTTP/1.1" 200 27235127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET /bg-upper.png HTTP/1.1" 200 3103127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET /bg-button.png HTTP/1.1" 200 713127.0.0.1 - - [28/Dec/2020:18:08:10 +0800] "GET /bg-middle.png HTTP/1.1" 200 1918127.0.0.1 - - [28/Dec/2020:18:08:12 +0800] "GET /TomExam/WebRoot/register.jsp HTTP/1.1" 404 729192.168.15.107 - - [28/Dec/2020:18:22:23 +0800] "GET / HTTP/1.1" 500 44990192.168.15.107 - - [28/Dec/2020:18:22:23 +0800] "GET /favicon.ico HTTP/1.1" 200 9662192.168.15.107 - - [28/Dec/2020:18:22:43 +0800] "GET /netBank/index.jsp HTTP/1.1" 200 4532192.168.15.107 - - [28/Dec/2020:18:22:52 +0800] "POST /user/user_login HTTP/1.1" 404 1404127.0.0.1 - - [28/Dec/2020:18:23:01 +0800] "GET /www/netBank/left.jsp HTTP/1.1" 403 1461192.168.15.107 - - [28/Dec/2020:18:23:53 +0800] "GET /ROOT/support_genuine.htm HTTP/1.1" 404 1404192.168.15.107 - - [28/Dec/2020:18:25:50 +0800] "GET /ROOT/WEB-INF/views/index.jsp HTTP/1.1" 403 1461192.168.15.107 - - [28/Dec/2020:18:26:07 +0800] "GET /ROOT/WEB-INF/views/head.jsp HTTP/1.1" 403 1461192.168.15.107 - - [28/Dec/2020:18:26:18 +0800] "GET /ROOT/WEB-INF/views/login.jsp HTTP/1.1" 403 1461192.168.15.107 - - [28/Dec/2020:18:27:35 +0800] "GET /TomExam/WebRoot/login.jsp HTTP/1.1" 500 3288192.168.15.107 - - [28/Dec/2020:18:28:38 +0800] "GET /TomExam/WebRoot/index.jsp HTTP/1.1" 500 2775
host-manager.YYYY-MM-DD.log
估计是放tomcat的自带的manager项目的日志信息的
谷歌这样说:
host-manager and manager the logs of the related web applications.
主机管理器Webapp的日志
我这里是空的
manager.YYYY-MM-DD.log
这个是tomcat manager项目专有的日志文件.

