以下是nginx.conf原文
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
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"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
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;
# }
#}
}
=====================================================================
原文结束,开始注解,首先是开头的全局部分
#首先开头这里是指定用户和工作的线程数数,开始是注释的,可以根据需要设置,例如,设置用户为root,线程数可以根据服务器核心数设置,设为核心数两倍或相同,但是更推荐设置为auto,这样自动根据 CPU 核心数设置工作进程数
user root;
worker_processes auto;
这一部分是日志记录和进程id,没什么好说的
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#进程id
#pid logs/nginx.pid;
原文
events {
worker_connections 1024;
}
events {#可以自己加工作模式如select,poll,kqueue,rtsig和/dev/poll模式,在日志中可以看到,一般设为epoll
use epoll;
#工作连接数,根据自己的需求和情况设置
worker_connections 1024;
}
往下是http模式
http {#这里这是nginx识别的文件类型
include mime.types;#这里设置了默认的类型为二进制流,也就是当文件类型未定义时使用,例如在没有配置asp的locate环境时,nginx不予解析,设置后用浏览器访问asp文件就会出现下载了
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"';#用来设置日志格式,和记录那些参数,默认main
#access_log logs/access.log main;
#是否下载上传文件,是的
sendfile on;
#tcp_nopush on;#超时时间
#keepalive_timeout 0;
keepalive_timeout 65;#gzip on;
#server模块
server {
#监听的端口,根据需要设置
listen 80;#这里设置的监听地址,默认是本机,根据需要更改,如改为
#server_name 123.123.123.12;
server_name localhost;#charset koi8-r;
#access_log logs/host.access.log main;
#主机基本设置,请求的url过滤,支持正则匹配,~为区分大小写,~*为不区分大小写。如果是 / 表示匹配所有的
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;
# }
#}}