ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
### Web配置 需创建扩展目录 ```shell mkdir -p /usr/local/nginx/conf/extra ``` #### 主配置文件 nginx.conf ```shell user nginx nginx; # 设置所有worker进程可以打开的最大文件句柄数 worker_rlimit_nofile 65535; worker_processes auto; worker_cpu_affinity auto; events { # 让多个worker进程轮询相应新请求 accept_mutex on; # 限制每个worker进程的并发连接数 worker_connections 10240; use epoll; } http { include mime.types; default_type application/octet-stream; # 开启高效文件传输模式 sendfile on; tcp_nodelay on; tcp_nopush on; # 设置客户端连接保持会话的超时时间 keepalive_timeout 10; # 设置客户端请求头读取超时时间 client_header_timeout 15; # 设置客户端请求主体读取超时时间 client_body_timeout 15; # 指定响应客户端的超时时间 send_timeout 15; # 设置最大的容许的客户端请求主体大小 client_max_body_size 10M; # 将http请求响应头里的nginx版本号信息隐藏 server_tokens off; # 开启压缩 gzip on; # 设置容许压缩的页面最小字节数 gzip_min_length 1k; # 申请4个单位为32K的内存作为压缩结果流缓存 gzip_buffers 4 32k; # 压缩的版本 gzip_http_version 1.1; # 由于IE6对Gzip压缩效果不好,建议在IE6的环境下关闭压缩功能 gzip_disable "MSIE[1-6]"; # 压缩比率 gzip_comp_level 3; # 指定压缩的类型 gzip_types text/plain text/css text/xml application/javascript application/x-javascript; # 设置从web服务器传给缓存服务器的时候不被解压。只有传送到用户后才解压缩 gzip_vary on; # 设置为Json格式,方便ELK日志分析软件处理 log_format json_main '{"@timestamp":"$time_iso8601",' '"remote_addr":"$server_addr",' '"remote_user":"$remote_user",' '"request_time":"$request_time",' '"request":"$request",' '"body_bytes_sent":"$body_bytes_sent",' '"request_method":"$request_method",' '"upstream_response_time":"$upstream_response_time",' '"upstream_addr":"$upstream_addr",' '"url":"$uri",' '"http_x_forwarded_for":"$http_x_forwarded_for",' '"http_referrer":"$http_referer",' '"status":"$status"}'; access_log logs/access.log json_main; error_log logs/error.log error; include extra/*.conf ; } ``` #### 扩展配置文件(便于管理) www.conf ```shell server { listen 8000; server_name www.noteshare.cn; root /data/noteshare/; set_real_ip_from 10.0.0.0/16; set_real_ip_from 192.168.0.0/16; real_ip_header X-Forwarded-For; real_ip_recursive on; location / { index index.html; } # 设置资源缓存时间 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 3650d; } # 设置资源缓存时间 location ~ .*\.(js|css)?$ { expires 30d; } # 设置状态页访问信息 location /ngx_status { stub_status on; access_log off; allow 192.168.0.0/16; deny all; } access_log logs/lego_access.log json_main; } ```