1、 docker pull nginx
mkdir -p /www/log mkdir -p /www/html 2、 docker run -p 8801:80 --name nginx01 -v /www:/www -v /www/log:/www/log -v /www/html:/www/html -v /etc/nginx.conf:/etc/nginx/nginx.conf -itd nginx
3、vi /etc/nginx.conf
worker_processes 4;
error_log /www/log/nginx_error.log crit; pid /www/nginx.pid; worker_rlimit_nofile 204800; events { use epoll; worker_connections 204800; } http { include mime.types; default_type application/octet-stream; charset utf-8; keepalive_timeout 60; sendfile on;
log_format main '[
remote_user] [
request" ' '
body_bytes_sent "
http_user_agent" "$http_x_forwarded_for"'; access_log /www/log/access.log access;
server_names_hash_bucket_size 128; client_header_buffer_size 2k; large_client_header_buffers 4 4k; client_max_body_size 8m;
open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s;
tcp_nopush on; tcp_nodelay on;
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;
server { listen 80; server_name 127.0.0.1; index index.php index.htm; root /www/html/; location / {
} location /status { stub_status on; } location ~ .*/.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } } }
4、日志切割
/www/log/access.log {
daily
rotate 30
create 644 root root
missingok
notifempty
compress
sharedscripts
postrotate
docker exec nginx01 bash -c "if [ -f /www/nginx.pid ]; then kill -USR1 docker exec nginx01 cat /www/nginx.pid
; echo 日志打包完毕; fi"
endscript
}
5、切割测试 logrotate -d -f /etc/logrotate.d/nginx01
logrotate -f /etc/logrotate.d/docker_nginx