#所有的设置必须以分号结尾
#user nobody; #只有被设置的用户或用户组才有权限启动nginx 如果希望所以的用户都能用:1 注销该设置 2 该值设置为 nobody
worker_processes 1; #并发处理请求的关键所在 理论上值越大越好但是也受环境的现在 可设置为 auto
#error_log logs/error.log; #错误日志的存放路径 和 级别 该值可以在全局块,http块,server块,或location块中配置
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; #nginx的进程的pid 可以为绝对路径也可以为相当安装目录的相对路径
events {
worker_connections 1024; #每个work process同时开启的最大连接数
#accept_mutex off #默认为开启状态 为防止”惊群“ 可设置为关闭 只能在event中进行设置
#multi_accept on #默认为关闭状态 即每个work process 只能接受一个新的请求
#use epoll; #配置事件驱动模型
}
http {
include mime.types; # 配置文件的引入 nginx作为web服务器(http的前两项配置),必须识别前台的请求资源类型 可以使用 cat mime.types 查看
default_type application/octet-stream;
#http块中的日志被成为服务日志 常用 access_log log_format 对日志的大小,格式 , 输出等进行配置
#log_format main '$remote_addr - $remote_user [$time_local] "$request" ' #log_format name string... name默认为combined 定义服务日志的格式,并取名方便access_log的调用 后面的字符串为单引号
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main; #access_log[format[buffer=size]] 存放路径和名称 + 可选的格式和缓冲区大小 可以在http块 server块和location块中进行设置
sendfile on; #sendfile() 传输文件 默认为关闭状态 , 这两个属性都是与传输文件相关,可以在HTTP块,server块,location块中进行设置
sendfile 128k; #表示nginx的sendfile()传输最大不能超过的数,如果该值为零表示没有限制,默认为0
#tcp_nopush on;
#keepalive_timeout 0; #keepalive_timeout timeout[timeout] 与请求连接保存的时间默认为75s 第二个值为浏览器的 Keep-Alive
keepalive_timeout 65;
#gzip on;
upstream backend { #nginx默认情况下是使用轮询方式请求 也可以设置为ip hash 这样可以共用session
#ip_hash;
server 10.30.1.1;
server 10.30.1.2;
server 10.30.1.3;
}
server {
#listen可以配置三种监听 分别是ip[port]监听 port 监听 和 UNIX Domain Socket 虽然可以进行复杂的设置,但是多数情况下一般使用如下
#listen 192.168.1.10:80 监听具体的ip和port
#listen 192.168.1.10 监听ip上的所有端口
#listen 8000 监听具体端口上的所有ip 等同于 listen *:000
#listen 192.168.1.10 dafault_server backlog=1024 设置192.168.1.10的链接请求默认由此虚拟主机处理,并且允许最大1024链接同时处于挂机状态
listen 80;
#虚拟主机配置,设置好主机名称和DNS,用户就可以通过它向虚拟主机发送请求了。可以配置多个名字中间用空格隔开,名字其实就是域名 如: www.myserver.com 名字可以只用通配符* 或者正则 只是正则以 ~ 标记 ^ 开始 $ 结束,
#当然虚拟主机也可以使用ip 进行配置 并且可以同时设置多个server 块
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#keepalive_requests 100; #限制用户用同一链接向服务器发送请求的次数 默认为100 可以在server块和location块中进行设置
# location块 location [ = | ~ | ~* | ^~ ] uri { ... } 该模块是用于请求的URL来匹配uri设置 可选的 = 表示严格匹配 ~ 表示正则区分大小写 ~* 表示正则不区分大小写 ^~ 表示找到匹配度最高的后立即执行请求
location / {
root html; #指定请求的根目录
#alias 路径; #更改请求的根目录
index index.html index.htm;
}
#网站请求的错误页面配置 error_page code ... [=[response ] ] uri code为错误编码 其他为可选项 该设置可以在http 块 ,server 块 和 location 块中进行设置
#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;
# }
#}
}