English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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: 구성 파일 /application/nginx-1.9.7/conf/nginx.conf 문법이 올바르습니다 nginx: 구성 파일 /application/nginx-1.9.7/conf/nginx.conf 테스트가 성공적입니다 [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 구성 파일의 server 태그에 다음 태그와 내용을 추가하세요
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-제어 번호-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: 구성 파일 /application/nginx-1.9.7/conf/nginx.conf 문법이 올바르습니다 nginx: 구성 파일 /application/nginx-1.9.7/conf/nginx.conf 테스트가 성공적입니다 [root@AnSheng conf]# /application/nginx-1.9.7/sbin/nginx -s reload
브라우저에서 도메인이나 IP를 입력하고 logs를 추가한 후 파일을 클릭하여 열 수 있습니다. 로그가 누구나 쉽게 확인할 수 있다면 매우 불안전합니다. 따라서 우리는 또一层 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: loguser 계정의 비밀번호 추가 # 비밀번호는 두 번 입력해야 합니다
9. Nginx 설정 파일을 편집하여 logs의 location에 다음 내용을 추가합니다
location /logs { ...... alias PATH; autoindex on; autoindex_exact_size off; autoindex_localtime on; add_header Cache-제어 번호-store; auth_basic "제한된"; # Nginx 인증 auth_basic_user_file /application/nginx-1.9.7/conf/loguser; # 인증 계정 비밀번호 저장 파일 }
10. 다시 열 때마다 계정과 비밀번호를 입력하도록 알림이 나타납니다. 로그인 후에만 확인할 수 있습니다.
11. 요약
이제 Nginx를 사용하여 브라우저가 실시간으로 방문 로그를 확인할 수 있는 모든 단계가 포함되어 있습니다. 여러분의 학습이나 업무에 도움이 되길 바랍니다. 궁금한 점이 있으시면 댓글로 교류해 주세요.