#Nginx用户及组:用户 组。window下不指定#user nobody;#错误日志:存放路径。worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid(进程标识符):存放路径#pid logs/nginx.pid;events {#单个进程最大连接数(最大连接数=连接数*进程数)worker_connections 1024;}http {#设定mime类型,类型由mime.type文件定义include mime.types;default_type application/octet-stream;#日志格式设置#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#用了log_format指令设置了日志格式之后,需要用access_log指令指定日志文件的存放路径#记录了哪些用户,哪些页面以及用户浏览器、ip和其他的访问信息#access_log logs/access.log main;#开启文件传输,一般应用都应设置为on;若是有下载的应用,则可以设置成off来平衡网络I/O和磁盘的I/O来降低系统负载sendfile on;#告诉nginx在一个数据包里发送所有头文件,而不一个接一个的发送。#tcp_nopush on;#长连接超时时间,单位是秒#keepalive_timeout 0;keepalive_timeout 65;#gzip模块设置,使用 gzip 压缩可以降低网站带宽消耗,同时提升访问速度。#gzip on;server {listen 80;# #IP/域名可以有多个,用空格隔开server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
第一部分 全局块
从配置文件开始到events块之前的内容,主要会设置一些影响 nginx服务器整体运行的配置指令。
比如默认配置中的 worker_processes 1; 工作进程:数目 。根据硬件调整,通常等于CPU数量或者2倍于CPU
第二部分 events块
events块 涉及的指令主要影响 Nginx 服务器与用户的网络连接
比如 worker_connections 1024; 单个进程最大连接数(最大连接数=连接数*进程数)
第三部分 http块
Nginx 服务器配置中修改最频繁的部分
http块也可以包括 http全局块、server块
