容器pod,k8s中nginx的日志路径位置

默认的位置是在容器里面:/var/log/nginx下的。

# pwd
/var/log/nginx
# ls -l
total 4
lrwxrwxrwx. 1 root root   11 Dec  2  2021 access.log -> /dev/stdout
lrwxrwxrwx. 1 root root   11 Dec  2  2021 error.log -> /dev/stderr

 这两个日志默认是输出到两个软连接里面的,但是查看这两个软连接又没有日志输出。

我需要自己设置日志存储位置,不用默认的,日志就会输出到我们自己设置的位置里面。

配置如下:

    http {
        error_log  /var/log/nginx/error2.log;
        access_log /var/log/nginx/access2.log;
		...
	   
	    }

或者

    server {
        listen       80;
        server_name  localhost;
	    
        error_log  /var/log/nginx/error2.log;
        access_log /var/log/nginx/access2.log;
               
        location / {
            root html;
            index  index.html index.htm;
        }


    }

重新启动一下容器

# ls -l
total 0
lrwxrwxrwx 1 root root 11 Dec  2  2021 access.log -> /dev/stdout
-rw-r--r-- 1 root root  0 Jun 19 07:00 access2.log
lrwxrwxrwx 1 root root 11 Dec  2  2021 error.log -> /dev/stderr
-rw-r--r-- 1 root root  0 Jun 19 07:00 error2.log

猜你喜欢

转载自blog.csdn.net/weixin_46627652/article/details/131287867