来自单页应用程序的 NGINX 访问日志

Kos*_*ylo 2 nginx

我有一个单页面应用程序的前端角度应用程序,具有以下 nginx 配置:

events{}
http {
    include /etc/nginx/mime.types;

    default_type  application/octet-stream;

    access_log  /var/log/nginx/access.log;

    server {
        listen 80;
        server_name localhost;
        root /usr/share/nginx/html;
        index index.html;
        location / {
            try_files $uri $uri/ $uri.html /index.html;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是访问日志仅在整个页面刷新时写入日志,而不是在每个用户操作(即单击页面的不同元素)中写入日志。

我希望能够记录每个用户操作,而不仅仅是在打开或刷新页面时。关于如何实现这一目标有什么建议吗?

Ger*_*der 12

不,这是不可能的。由于它只是一个页面,因此这就是从服务器检索的全部内容。其他一切都纯粹发生在客户端,没有进一步的请求发送到服务器。

您需要在每次点击时发送 AJAX 请求才能记录它。