您的位置:首页 > 运维架构 > Nginx

nginx快速入门之nginx.conf配置注解说明

2014-12-01 16:51 399 查看
以下是windows版本 nginx配置文件注解说明

#user nobody;
#启动进程数量,一般设置成cpu数量
worker_processes 2;

#全局错误日志以及PID文件
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;#单个后台worker process进程的最大并发连接数
}

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"';
#设定日志格式
#access_log logs/access.log main;

#sendfile 指令指定 Nginx 是否调用 sendfile 函数( zero copy 方式)来输出文件,
#对于普通应用,必须设为 on, 如果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off,
#以平衡磁盘与网络 I/O 处理速度,降低系统的 uptime
sendfile on;
#tcp_nopush on;

#连接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;

#开启 gzip 压缩
#gzip on;

server {
#侦听80端口
listen 80;
#定义使用localhost访问
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;
}

#静态文件, Nginx 自己处理

location ~ ^/(images|javascript|js|css|flash|media|static)/ {

root /var/www/virtual/htdocs;

#过期 30 天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点
expires 30d;
}

# 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;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

server {
listen 80;
server_name web.tianyi9703.com;
location / {
proxy_pass http://127.0.0.1:8080;#代理web节点地址 }
location ~* ^.+\.(gif|css|js|txt|xml|swf|wav)$ {
root E:\apache-tomcat-7.0.27\webapps;#静态化文件地址,用户提供缓存
access_log off;
expires 24h;
}
## Serve an empty 1x1 gif _OR_ an error 204 (No Content) for favicon.ico
location ~(favicon.ico) {
break;
}
}

}

#user nobody;
#启动进程数量,一般设置成cpu数量
worker_processes 2;

#全局错误日志以及PID文件
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;#单个后台worker process进程的最大并发连接数
}

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"';
#设定日志格式
#access_log logs/access.log main;

#sendfile 指令指定 Nginx 是否调用 sendfile 函数( zero copy 方式)来输出文件,
#对于普通应用,必须设为 on, 如果用来进行下载等应用磁盘 IO 重负载应用,可设置为 off,
#以平衡磁盘与网络 I/O 处理速度,降低系统的 uptime
sendfile on;
#tcp_nopush on;

#连接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;

#开启 gzip 压缩
#gzip on;

server {
#侦听80端口
listen 80;
#定义使用localhost访问
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;
}

#静态文件, Nginx 自己处理

location ~ ^/(images|javascript|js|css|flash|media|static)/ {

root /var/www/virtual/htdocs;

#过期 30 天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点
expires 30d;
}

# 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;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

server {
listen 80;
server_name web.tianyi9703.com;
location / {
proxy_pass http://127.0.0.1:8080;#代理web节点地址 }
location ~* ^.+\.(gif|css|js|txt|xml|swf|wav)$ {
root E:\apache-tomcat-7.0.27\webapps;#静态化文件地址,用户提供缓存
access_log off;
expires 24h;
}
## Serve an empty 1x1 gif _OR_ an error 204 (No Content) for favicon.ico
location ~(favicon.ico) {
break;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx