【问题标题】:NGINX access.log not updatingNGINX access.log 未更新
【发布时间】:2020-06-20 17:14:35
【问题描述】:

我创建了一个带有 4 个 html 页面(4 个链接)的简单 HTML 网站。 access.log 不会因多次访问 html 页面而更新。


例如用户点击链接#1 -> 链接#2 -> 链接#1

access.log 只会显示:

GET /page#1.html

GET /page#2.html

我希望它显示所有请求,即:

GET /page#1.html

GET /page#2.html

GET /page#1.html


我已经研究过定制我的 .config 文件,但没有成功。 任何帮助将不胜感激。 谢谢。

这是我的 nginx.config 文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 2048;
    multi_accept on;
}

http {

##
# Basic Settings
##

server_name_in_redirect off;
server_tokens off;
port_in_redirect off;

sendfile on;
tcp_nopush on;
tcp_nodelay off;
send_timeout 30;
keepalive_timeout 60;
keepalive_requests 200;
reset_timedout_connection on;
types_hash_max_size 2048;

server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
#default_type application/octet-stream;
default_type text/html;
charset UTF-8;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;

##
# Gzip Settings
##

gzip on;
gzip_min_length 256;
gzip_disable "msie6";

# gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

【问题讨论】:

  • 因为没有对服务器的请求。您的浏览器缓存了该文件。你没检查控制台吗?
  • @emix 您好,感谢您的快速回复,我对网络比较陌生。当用户返回第 1 页时,为什么没有对服务器的请求?
  • 我已经解释过了:文件在浏览器的缓存中。按 F12,控制台就是你的朋友。
  • @emix 我知道请求在浏览器的缓存中,我可以在控制台中看到它们。但是单个页面的多个请求没有被缓存到我的 access.log 文件中。似乎网页在第一次请求时被加载到用户的系统,因此,它不需要在该网页的第二次请求时向服务器发送另一个请求。
  • 那么你的问题是什么?然后你可以告诉 nginx 告诉浏览器不要缓存 html 文件。

标签: nginx logging server configuration access-log


【解决方案1】:

正如@emix 已经指出的那样,浏览器根本不会向您的服务器发出请求。相反,该页面很可能会从您的浏览器缓存中提供。

浏览器为什么这样做的(太)简短的答案是减少不必要的网络请求并节省资源。

为了更好地了解(浏览器)缓存是什么,我建议您阅读以下资源:

Stackoverflow 问答

外部网站:

【讨论】:

  • 感谢 Tom & emix 的帮助!这个问题是有道理的。我现在读一读:)
猜你喜欢
  • 2018-11-01
  • 2023-03-12
  • 2012-03-22
  • 1970-01-01
  • 2019-01-21
  • 1970-01-01
  • 2019-10-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多