nginx configuration filenginx.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;
}
All subsite configuration files are not configured with access_log off
The following is a subsite configuration filevhost/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;
}
There are many subsite configuration files, but access_log off is not configured
After passing the above configuration, every time the nginx/logs/access.log
log file is deleted, a new access.log log file will be generated the next day, with a size of about 1G. The company's requirement is to turn off nginx's access.log function, which means not allowing nginx to record access logs. Does anyone have a better solution? Thank you so much!
phpcn_u15822017-05-16 17:18:07
The answer has been found.
Actually, it’s said on the Internet access_log /dev/null;
只是针对nginx的error_log而言的。如果想关闭error_log
,那么就用error_log /dev/null
(see what foreigners do).
But want to closeaccess_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;
.
Pure practical experience in production environment.