Nginx directory file list display

The project uses tomcat, Nginx, the testing phase, the production phase often some bug needs to be investigated.
Need some log management tool, in the absence of ELK circumstances, you can be achieved by configuring the basic daily view nginx. Do not need to log on to the Linux server, you can quickly get the log files through a browser.

Development and testing environment suitable for production environments with caution.

planning:

1. Prepare by nginx web query logs: / var / log / nginx
2. tomcat ready to view logs by web: / opt / tomcat / logs
3. queries users to upload a folder: / opt / upload /

First on renderings:

 
TUP

nginx configuration

If nginx installation configuration, this online a lot, not much to say.
According to the official nginx demo sample configuration:
/etc/nginx/conf.d -- conf.d 配置目录。
create a new file in which:  port--8000.conf(a custom file name)

Configuration file as follows,

server {
    listen       8000;
    server_name  xxx.com; location /log/nginx/ { alias /var/log/nginx/; #Nginx日志目录 autoindex on; #打开目录浏览功能 autoindex_exact_size off; #默认为on,显示出文件的确切大小,单位是bytes #显示出文件的大概大小,单位是kB或者MB或者GB autoindex_localtime on; #默认为off,显示的文件时间为GMT时间。 #改为on后,显示的文件时间为文件的服务器时间 add_header Cache-Control no-store; #让浏览器不保存临时文件 } location /log/tomcat/ { alias /opt/tomcat/logs/; autoindex on; autoindex_exact_size off; autoindex_localtime on; add_header Cache-Control no-store; } location /log/upload/ { alias /opt/upload/; autoindex on; autoindex_exact_size off; autoindex_localtime on; add_header Cache-Control no-store; } } 

Here it is configured with multiple location. Note the path ok.
`

Restart nignx,

nginx -t 
nginx -s reload 

Then modified: browser to view the results.
localhost:8000/log/nginx/
localhost:8000/log/tomcat/
localhost:8000/log/upload/

Some parameters:

autoindex on; # to open the file directory list
autoindex_exact_size on; # display the exact size of the file, the unit is bytes
autoindex_localtime ON; file # Display time for a file server time
charset utf-8, gbk; # avoid Chinese garbled

Further, if desired requested file is downloaded instead of displaying content, can be achieved by adding the following parameters:
the add_header the Content-Disposition Attachment;

Nginx can achieve using the browser to view real-time access log of all the steps, I want to study or work helpful, if in doubt you can leave a message exchange.

Guess you like

Origin www.cnblogs.com/surplus/p/11441186.html