nginx 配置详解

2025-07-17 09:25:38

1、【nginx.conf基本组成】:xxxxxevents{xxxxx}http{xxxxxserver{xxxxx}server{xxxxx}xxxxx}

nginx 配置详解
nginx 配置详解
nginx 配置详解

2、【头部】:user-是nginx进程用户名;worker_processes-是nginx工作进程数量,建议设置为cpu核心数量的2倍;pid-是nginx进程pid的存放文件。

nginx 配置详解

3、【events部分】:worker_connections是每个工作进程允许最大的同时连接数 量。

nginx 配置详解

4、【http部分】:主要是server虚拟主机部分的配置。以下详细讲解。

nginx 配置详解

5、【nginx虚拟主机】:server{listen端口;server_name192.168.1.166;......}server_name可以是ip地址也可以是域名,可以添加多个用空格分开。

nginx 配置详解

6、【日志格式设置和路径】:og_format设置日志格式log_formatnameformat[format...]name:定义格式名称format:定义格式样式默认格式:combined'$remote_addr-$remote_user[$time_local]''"$request"$status$body_bytes_sent''"$http_referer""$http_user_agent"';access_log指定日志文件存放路径access_logpath[format[buffer=size|off]]path:文件存放路径format:log_format定义格式的名称buffer:内存缓冲区大小使用默认格式:access_logpath;使用缓冲加速日志文件读写:open_log_file_cachemax=N[inactive=time][min_uses=N][valid=time]|off(默认)max:缓存最大文件描述符数量,超过使用LRU算法淘汰inactive:在inactive指定时间内文件描述符没有被使用则被自动删除,默认10秒min_uses:在inactive指定时间内,文件描述符超过min_uses使用次数,则加入缓存,默认1valid:查看变量指定的日志文件路径与文件是否存在的时间间隔,默认60秒

nginx 配置详解

7、【压缩输出】:gzip压缩后变为原来的<=30%配置:gzipon;gzip_min_length1k;gzip_buffers416k;gzip_http_version1.1;gzip_comp_level2;gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;gzip_varyon;

nginx 配置详解

8、【自动列出目录和location】:location/{autoindexon;打开自动列出目录autoindex_exact_size[on|off]索引文件大少单位(BKBMBGB)autoindex_localtime[on|off]开启本地时间显示文件时间}

nginx 配置详解

9、【浏览器本地缓存】:expires[time|epoch|max|off]time时间值负数不缓存epoch设定为1january,1970,00:00:01GMTmax设定为31December203723:59:59GMT

10、【php fastcgi】:location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; }

nginx 配置详解
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:69
  • 阅读量:42
  • 阅读量:39
  • 阅读量:80
  • 阅读量:31
  • 猜你喜欢