nginx gagal menutup access.log
黄舟
黄舟 2017-05-16 17:16:07
0
2
1191

fail konfigurasi nginxnginx.conf:

user  www www;


worker_processes 8;

worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65536;

events
    {
        use epoll;
        worker_connections 65536;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        open_file_cache max=102400 inactive=20s;
        open_file_cache_valid 30s;
        open_file_cache_min_uses 1;

        sendfile on;
        tcp_nopush     on;

        keepalive_timeout 90;

        tcp_nodelay on;

        fastcgi_connect_timeout 1200;
        fastcgi_send_timeout 1200;
        fastcgi_read_timeout 1200;
        fastcgi_buffer_size 256k;
        fastcgi_buffers 16 256k;
        fastcgi_busy_buffers_size 512k;
        fastcgi_temp_file_write_size 1024k;
        fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
                keys_zone=TEST:10m
                inactive=5m;
                         


        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types       text/plain application/x-javascript text/css application/xml;
        gzip_vary on;
        gzip_proxied        expired no-cache no-store private auth;
        gzip_disable        "MSIE [1-6]\.";

        #limit_zone  crawler  $binary_remote_addr  10m;

        server_tokens off;
        #log format
        #log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                 #'$status $body_bytes_sent "$http_referer" '
                 #'"$http_user_agent" $http_x_forwarded_for';
        
        # 关闭access.log
        access_log /dev/null;

server
    {
        listen       80;
        server_name aaa.abc.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/abc.com;

        location ~ ^/(abc_status)$ 
            {
                include fcgi.conf;
                fastcgi_pass unix:/tmp/php-cgi.sock;
            }
        location ~ .*\.(php|php5)?$
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                include fcgi.conf;
            }

        location /status {
            stub_status on;
            #access_log /dev/null;
        }
        location /guide{
            rewrite ^([^\.]*)/wenda/(\w+)/(\w+)\.html$ /index.php?r=wenda// last;
            rewrite ^([^\.]*)/([a-zA-Z]+)/([a-zA-Z]+)\.html$ /index.php?r=/ last;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

        location ~ .*\.(js|css)?$
            {
                expires      12h;
            }
    
    # 关闭access.log
    access_log off;

    # access_log  /home/wwwlogs/access.log  access;
    }
include vhost/*.conf;
}


Semua fail konfigurasi subtapak tidak dikonfigurasikan dengan access_log off

Berikut ialah fail konfigurasi subtapakvhost/app3.abc.com.conf:

server
    {
        listen       80;
        server_name app3.abc.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/abc.com/guide;
        location ~ .*\.(php|php5)?$
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                include fcgi.conf;
            }
        location /{

            rewrite ^([^\.]*)/wenda/(\w+)/(\w+)\.html$ /index.php?r=wenda// last;

            #rewrite ^([^\.]*)/([a-zA-Z]+)/([a-zA-Z]+)\.html$ /index.php?r=/ last;        
                        
            if (!-e $request_filename) {
                return 404;
            }
        }
        
        location /ueditor{
            autoindex on;
            }        
        
        location ~ .*\.(gif|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

        location ~ .*\.(js|css)?$
            {
                expires      12h;
            }

        #access_log  /home/wwwlogs/visit.log  access;
        error_log  /home/wwwlogs/wenda_error.log  crit;
        }

Terdapat banyak fail konfigurasi subtapak, tetapi tiada satu pun daripada mereka mempunyai akses_log off dikonfigurasikan

Selepas melepasi konfigurasi di atas, setiap kali nginx/logs/access.logfail log dipadamkan, fail log akses.log baharu akan dijana pada keesokan harinya, iaitu bersaiz lebih kurang 1G. Keperluan syarikat adalah untuk mematikan fungsi access.log nginx, yang bermaksud tidak membenarkan nginx merekod log akses. Adakah sesiapa mempunyai penyelesaian yang lebih baik? Terima kasih banyak-banyak!

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

membalas semua(2)
phpcn_u1582

Jawapan telah ditemui.

Malah, access_log /dev/null; yang disebut di Internet hanyalah untuk error_log nginx. Jika anda ingin mematikan error_log, kemudian gunakan error_log /dev/null (lihat cara orang asing melakukan ini). access_log /dev/null; 只是针对nginx的error_log而言的。如果想关闭error_log,那么就用error_log /dev/null(看老外是这么做的)。

但是想关闭access_log的话,直接在nginx.conf的http模块中配置access_log off;即可。需要注意的是,已经继承了http模块的那些模块不要再设置access_log off;了。 比如,我已经在http模块中设置了access_log off;,那么就不要在http模块所包含的server模块或location模块中设置access_log off;,以及虚拟主机目录(vhost)下的配置文件也不要添加access_log off;

Tetapi jika anda ingin mematikan log_akses, hanya konfigurasikan log off_akses; terus dalam modul http nginx.conf. Perlu diingatkan bahawa modul-modul yang telah mewarisi modul http seharusnya tidak lagi menetapkan access_log off;. Sebagai contoh, jika saya telah menetapkan access_log off; dalam modul http, maka jangan tetapkan access_log off; dalam modul pelayan atau modul lokasi yang disertakan dalam modul http, dan maya Jangan tambah access_log off; pada fail konfigurasi di bawah direktori hos (vhost).

Pengalaman praktikal murni dalam persekitaran pengeluaran. 🎜
仅有的幸福

Bolehkah anda mengkonfigurasi laluan log ke /dev/null?

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!