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

Nginx的配置文件说明

2011-10-14 13:44 381 查看
Nginx的配置文件说明

基本上都有注释啦:

#user命令指定运行nginx进程的用户和组。如果未指定则默认与当前运行的用户相同

#user nobody;

#启动进程。使nginx可以使用多个CPU

worker_processes 1;

#全局错误日志及PID文件

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#nginx.pid文件记录着当前nginx主进程的ID号

#pid logs/nginx.pid;

#工作模式及连接数上限

events {

#设置每个工作进程可以处理的连接数

worker_connections 1024;

}

#设定http服务器,利用它的反向代理功能提供负载均衡支持

http {

#设定mime类型

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模块

gzip on;

#允许压缩的页面最小字节数,默认为0(多大的文件都压缩)建议大于1k,否则有可能越压越大

gzip_min_length 1k;

#设置系统获取几个单位的缓存来存储gzip的压缩结果数据流(要4的倍数),默认是申请原始数据相同大小的内存空间

gzip_buffers 4 16k;

#识别HTTP的版本,以防早期浏览器不支持gzip(1.0|1.1)

gzip_http_version 1.1;

#gzip压缩比,1-9(1压缩比最小处理速度最快,9压缩比最高处理速度最慢)

gzip_comp_level 2;

#匹配mine类型进行压缩(无论是否指定,text/html类型总是会被压缩)

gzip_types text/plain application/x-javascript text/css application/xml;

#gzip_vary on;

#定义一个数据区,记录会话状态信息

#定义一个叫做 one 的数据区,总容量为10MB,以变量$binary_remote_addr(长度为4bytes,会话信息长度为32bytes)为会话的判断基准(一个地址一个会话)

#当记录区大小为1MB时,大约可以记录32000个会话信息

limit_zone one $binary_remote_addr 10m;

#默认虚拟主机

server {

#监听端口(只有IP则默认80端口)

#listen 127.0.0.1;

#listen 127.0.0.1:8000;

#listen *:8000;

listen 81;

#指定主机名称(根据客户端请求Header头信息中的Host域名信息,来匹配改请求应该由哪个主机配置server{...}来处理)

server_name localhost:81;

#添加文本编码类型到HTTP应答头“content-type ”

#charset off;

#charset koi8-r;

charset utf-8;

access_log logs/mainhost.access.log ;

#允许或禁止自动目录列表

#autoindex off;

#设置目录列表中显示文件大小的单位

#autoindex_exact_size on;

location / {

#设置网站默认首页文件

index index.html index.htm index.php;

#设置网站根目录

root d:/web/php;

}

location ^~ /a/ {

proxy_pass http://localhost:81;
proxy_redirect off;

proxy_set_header X-Real-IP $remote_addr;

}

#设置单连接限速条件(当下载文件字节数超过1MB后,limit_rate限速生效,限速100k)

#limit_rate_after 1m;

#单连接限速

#limit_rate 100k;

#设置某个目录

location /download/ {

#设置目录默认首页文件

#index index.html index.htm index.php;

#指定一个会话最大的并发连接数(与之前的limit_zone配合使用),限制在download目录下,一个IP只能发起一个连接,多于1个,一律返回Services unavailable(503)状态

limit_conn one 1;

}

#设定查看Nginx状态的地址

location /NginxStatus {

stub_status on;

access_log on;

auth_basic "NginxStatus";

}

#错误日志

error_log logs/server_error.log error;

#指定404错误页面,不得大于512字节

#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 d:/web/php;

#禁用404错误日志,可以禁止nginx记录找不到robots.txt 和 favicon.ico 这类文件的错误信息。

log_not_found off;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#将客户端的请求转交给fastcgi

location ~ .*\.(php|php5)?$ {

#location ~ \.php$ {

# root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME d:/web/php$fastcgi_script_name;

include fastcgi_params;

}

#网站的图片较多,更改较少,将它们在浏览器本地缓存15天

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 15d;

}

#网站会加载很多JS、CSS,将它们在浏览器本地缓存1天

location ~ .*\.(js|css)?$

{

expires 3d;

}

}

#ZenTaoPMS配置

server {

listen 84;

server_name localhost:84;

charset utf-8;

access_log logs/ZenTaoPMSsaccess.log ;

error_log logs/ZenTaoPMS_error.log error;

location / {

index index.html index.htm index.php;

root d:/web/php/ZenTaoPMS/www;

autoindex on;

}

location ~ .*\.(php|php5)?$ {

#root d:/web/php/ZenTaoPMS/www;

fastcgi_pass 127.0.0.1:9001;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME d:/web/php/ZenTaoPMS/www$fastcgi_script_name;

include fastcgi_params;

}

}

# 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 ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

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