>  기사  >  운영 및 유지보수  >  Nginx는 어떻게 브라우저가 실시간으로 액세스 로그를 볼 수 있도록 합니까?

Nginx는 어떻게 브라우저가 실시간으로 액세스 로그를 볼 수 있도록 합니까?

WBOY
WBOY앞으로
2023-05-15 12:31:221398검색

1. 먼저 nginx 버전을 확인하세요. 저는 1.9.7 버전을 사용하고 있습니다. 설치 디렉터리는 /application/nginx-1.9.7

[root@ansheng ~]# /application/nginx-1.9.7/sbin/nginx -v
nginx version: nginx/1.9.7
built by gcc 4.4.7 20120313 (red hat 4.4.7-16) (gcc)
configure arguments: --prefix=/application/nginx-1.9.7 --user=nginx --group=nginx --with-http_stub_status_module

2입니다. 구문을 확인하고 nginx

[root@ansheng ~]# /application/nginx-1.9.7/sbin/nginx -t
nginx: the configuration file /application/nginx-1.9.7/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.9.7/conf/nginx.conf test is successful
[root@ansheng ~]# /application/nginx-1.9.7/sbin/nginx

3. nginx 구성 파일

[root@ansheng ~]# cd /application/nginx-1.9.7/conf/
[root@ansheng conf]# egrep -v "#|^$" nginx.conf.default
worker_processes 1;
events {
 worker_connections 1024;
}
http {
 include mime.types;
 default_type application/octet-stream;
 sendfile on;
 keepalive_timeout 65;
 server {
  listen 80;
  server_name localhost;
  location / {
   root html;
   index index.html index.htm;
  }
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
   root html;
  }
 }
}
[root@ansheng conf]# egrep -v "#|^$" nginx.conf.default nginx.conf

에서 중복된 주의 줄과 빈 줄을 삭제합니다. 4. nginx 구성 파일

location /logs {
 alias /application/nginx-1.9.7/logs;
 #nginx日志目录

 autoindex on;
 #打开目录浏览功能

 autoindex_exact_size off;
 #默认为on,显示出文件的确切大小,单位是bytes
 #显示出文件的大概大小,单位是kb或者mb或者gb

 autoindex_localtime on;
 #默认为off,显示的文件时间为gmt时间。
 #改为on后,显示的文件时间为文件的服务器时间

 add_header cache-control no-store;
 #让浏览器不保存临时文件
}

의 서버 태그에 다음 태그와 콘텐츠를 추가합니다. 5. 브라우저에서 로그 파일을 엽니다. 그렇지 않은 경우 전원을 켜고 파일을 클릭하면 열리지 않고 다운로드됩니다

[root@ansheng conf]# vim mime.types
types {
 text/html html htm shtml;
 text/log log;
 text/css css;
 text/xml xml;
 .............

6. 구문을 확인한 다음 nginx 구성이 적용되도록 하고 브라우저에서 확인하세요

[root@ansheng conf]# /application/nginx-1.9.7/sbin/nginx -t
nginx: the configuration file /application/nginx-1.9.7/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.9.7/conf/nginx.conf test is successful
[root@ansheng conf]# /application/nginx-1.9.7/sbin/nginx -s reload

Open 브라우저에 도메인 이름이나 IP를 입력하고 그 뒤에 로그를 추가한 다음 파일을 열 수 있습니다. 로그를 다른 사람이 무심코 볼 수 있다면 안전하지 않은 걸까요? 따라서 nginx 사용자 인증 계층을 추가해야 합니다.

Nginx는 어떻게 브라우저가 실시간으로 액세스 로그를 볼 수 있도록 합니까?

Nginx는 어떻게 브라우저가 실시간으로 액세스 로그를 볼 수 있도록 합니까?

7. 계정 및 비밀번호 생성을 위해 httpd-tools 설치

[root@ansheng ~]# yum -y install httpd-tools

8. 인증된 계정 생성

[root@ansheng ~]# htpasswd -c /application/nginx-1.9.7/conf/loguser loguser
new password:
re-type new password:
adding password for user loguser
#密码需要输入两次

9. nginx 구성 파일을 편집하고 해당 위치에 다음을 추가합니다. 로그 내용

location /logs {
 ......
 alias path;
 autoindex on;
 autoindex_exact_size off;
 autoindex_localtime on;
 add_header cache-control no-store;
 auth_basic "restricted";
 #nginx认证
 auth_basic_user_file /application/nginx-1.9.7/conf/loguser;
 #认证账号密码保存的文件
}

10. 그러면 열면 계좌번호와 비밀번호를 입력하라는 메시지가 나오며, 로그인해야만 볼 수 있습니다.

Nginx는 어떻게 브라우저가 실시간으로 액세스 로그를 볼 수 있도록 합니까?

위 내용은 Nginx는 어떻게 브라우저가 실시간으로 액세스 로그를 볼 수 있도록 합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제