Nginx Implementation Browser can view the access log in real time steps detailed _nginx

Source: Internet
Author: User
Tags log log egrep

First, look at the Nginx version, I use the 1.9.7 version, the installation directory in/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

Second, check the grammar and start Nginx

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

Delete the extra gaze line and blank line in the Nginx configuration file

[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;
 server {
  listen;
  server_name localhost;
  Location/{
   root html;
   Index index.html index.htm;
  }
  Error_page 502 503 504/50x.html;
  Location =/50x.html {
   root html;
  }
}} [Root@ansheng conf]# egrep-v "#|^$" Nginx.conf.default nginx.conf

Iv. Add the following tags and contents to the Server tab of the Nginx configuration file

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

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

 autoindex_exact_size off;
 #默认为on, display the exact size of the file, in bytes
 #显示出文件的大概大小, in KB or MB or GB

 autoindex_localtime on;
 #默认为off, the file time displayed is GMT time.
 #改为on后, the file time shown is Add_header Cache-control no-store for the file's server time

 ;
 #让浏览器不保存临时文件
}

Open the log file in the browser, if you do not open and then click on the file download instead of opening

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

Test syntax, and then let the Nginx configuration take effect in the browser view

[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 the browser to enter the domain name or IP, followed by logs, and then click on the file can be opened, if the log casually can be viewed by others is not very safe, so we have to add a layer of Nginx user authentication.

Vii. installation of Httpd-tools for account password generation

[Root@ansheng ~]# yum-y Install Httpd-tools

Eight, create the certified account

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

Nine, edit nginx configuration file, add the following content in logs location

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;
 #认证账号密码保存的文件
}

Ten, and then open the time will be prompted to enter the account and password, after landing can be viewed.

Xi. Summary

The above is the use of Nginx to achieve real-time browser access to the log of all the steps, I hope that the study or work to help, if you have questions you can message exchange.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.