Home Operation and Maintenance Nginx How does Nginx enable the browser to view access logs in real time?

How does Nginx enable the browser to view access logs in real time?

May 15, 2023 pm 12:31 PM
nginx Browser

1. First check the nginx version. I am using version 1.9.7. The installation directory is /application/nginx-1.9.7

1

2

3

4

[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

Copy after login

2. Check Grammar and start nginx

1

2

3

4

[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

Copy after login

3. Delete the redundant attention lines and blank lines in the nginx configuration file

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

[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

Copy after login

4. In nginx Add the following tags and content to the server tag of the configuration file

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

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;

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

}

Copy after login

5. Enable the log file to be opened in the browser. If it is not enabled, it will be downloaded instead of opened when you click the file

1

2

3

4

5

6

7

[root@ansheng conf]# vim mime.types

types {

 text/html html htm shtml;

 text/log log;

 text/css css;

 text/xml xml;

 .............

Copy after login

6. Check the syntax, then let the nginx configuration take effect, view it in the browser

1

2

3

4

[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

Copy after login

Open the browser and enter the domain name or IP, add logs after it, and then click The file can be opened. Is it unsafe if the log can be viewed by others casually, so we need to add a layer of nginx user authentication.

How does Nginx enable the browser to view access logs in real time?

How does Nginx enable the browser to view access logs in real time?

##7. Install httpd-tools for account and password generation

1

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

Copy after login

8. Create a certified account

1

2

3

4

5

[root@ansheng ~]# htpasswd -c /application/nginx-1.9.7/conf/loguser loguser

new password:

re-type new password:

adding password for user loguser

#密码需要输入两次

Copy after login

9. Edit the nginx configuration file and add the following content to the logs location

1

2

3

4

5

6

7

8

9

10

11

12

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;

 #认证账号密码保存的文件

}

Copy after login

10 , and then when you open it again, you will be prompted to enter your account number and password, and you can view it only after logging in.

How does Nginx enable the browser to view access logs in real time?

The above is the detailed content of How does Nginx enable the browser to view access logs in real time?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

How to customize the resize symbol through CSS and make it uniform with the background color? How to customize the resize symbol through CSS and make it uniform with the background color? Apr 05, 2025 pm 02:30 PM

The method of customizing resize symbols in CSS is unified with background colors. In daily development, we often encounter situations where we need to customize user interface details, such as adjusting...

How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? How to correctly display the locally installed 'Jingnan Mai Round Body' on the web page? Apr 05, 2025 pm 10:33 PM

Using locally installed font files in web pages Recently, I downloaded a free font from the internet and successfully installed it into my system. Now...

The text under Flex layout is omitted but the container is opened? How to solve it? The text under Flex layout is omitted but the container is opened? How to solve it? Apr 05, 2025 pm 11:00 PM

The problem of container opening due to excessive omission of text under Flex layout and solutions are used...

Why does negative margins not take effect in some cases? How to solve this problem? Why does negative margins not take effect in some cases? How to solve this problem? Apr 05, 2025 pm 10:18 PM

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

How to obtain real-time application and viewer data on the 58.com work page? How to obtain real-time application and viewer data on the 58.com work page? Apr 05, 2025 am 08:06 AM

How to obtain dynamic data of 58.com work page while crawling? When crawling a work page of 58.com using crawler tools, you may encounter this...

How to use CSS and Flexbox to implement responsive layout of images and text at different screen sizes? How to use CSS and Flexbox to implement responsive layout of images and text at different screen sizes? Apr 05, 2025 pm 06:06 PM

Implementing responsive layouts using CSS When we want to implement layout changes under different screen sizes in web design, CSS...

Why does a specific div element in the Edge browser not display? How to solve this problem? Why does a specific div element in the Edge browser not display? How to solve this problem? Apr 05, 2025 pm 08:21 PM

How to solve the display problem caused by user agent style sheets? When using the Edge browser, a div element in the project cannot be displayed. After checking, I posted...

See all articles