全局配置指令

1.用户权限

在root用户下启动的nginx,在普通用户看不到

user  xxx;

2.进程

master_process  主工作进程,默认 on  还可以是off

work_process  指定数量/auto  

3.守护进程

daemon    on/off  默认开启,如果设置成off则 控制台结束时,关闭nginx

4.指定PID

指令存放当前PID的路径,默认是

nginx 基本配置_nginx

 

5.错误日志

error_log 

nginx 基本配置_html_02

可以指定路径或者默认级别

error_log不仅可以配置到全局,还可以配置到http server location

 

nginx 基本配置_nginx_03

6.多配置文件

include  xx.conf

 

events配置

1.accept_mutex   网络连接序列化

 on/off    默认on

解决惊群问题,一个客户端请求多个work进程同时被唤醒,但只有一个会被连接到。 on表示挨个被唤醒

 

2.multi_accept

是否允许同时接收多个网络连接,否则一个工作进程可以同时接收所有新连接

on/off    默认off

 

3.worker_connectiions

单个进程最大连接数,这里的连接数不仅包括和前端用户,还包括所有可能的连接数。

连接数值不能大于操作系统支持打开的最大文件句柄数

 

4.use

用来设置nginx服务器选择哪种事件驱动来处理网络消息

select poll epoll kqueue

 

http配置

 mime-type  网络传输的类型

默认

include mime.types;
default_type application/octet-stream;

 可以放在http server location中

 

日志

access_log 记录用户所有的访问请求    

error_log 记录nginx运行时错误

单独开一篇

 

sendfile 

处理静态资源的效率

是否使用sendfile()传输文件 默认off

可以放在http server location中

 

keepalive_timeout

长连接的超时时间 默认75s

keepalive_timeout 75

 

keepalive_requests

一个长连接使用的次数

keepalive_requests 200;

可以放在http server location中

 

server

一个http可以有多个server

listen

servername

location

error_page  

 

 

#worker进程数,默认一个。 可以设置成为 cpu数量或者cpu2倍的数量
worker_processes 1;

events{
#配置单个进程的最大连接数,单个最大可设置为65535。总的连接数=连接数*进程数。
worker_connections 1024;
}

http{
server{
location /{
root www;
#index index.html;
}
}
}

 

 

 

#启动worker进程用户,默认nobody
#user nobody;

#worker进程数目,默认一个。 可以设置成为 cpu数量或者cpu2倍的数量
worker_processes 1;

#日志登记可以是 debug info notice warn error crit ,默认是error
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#配置进程id,在 logs文件夹下有个nginx.pid文件,里面只有一个数值,这个数值就是进程id
#pid logs/nginx.pid;



#配置工作模式和连接数
events {
#配置单个进程的最大连接数,单个最大可设置为65535。总的连接数=连接数*进程数。
worker_connections 1024;
}


#http配置
http {
###########基本配置####################

#支持哪些多媒体文件,在/usr/local/nginx/conf 下mime.types文件里有一个列表
include mime.types;

#默认类型流类型,
default_type application/octet-stream;

#配置日志格式,向$remote_addr这些是nginx内部变量
#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;


############服务配置###################

server {

#监听端口
listen 80;

#可以通过任何ip和域名都可以访问本服务器
server_name localhost;

#字符集
#charset koi8-r;

#也是日志,如果上面配置了日志,以本日志为主
#access_log logs/host.access.log main;

location / {
#根目录位置,默认在xxxxxx/nginx/html下的 index.html
root html;
index index.html index.htm;
}

#配置404时的页面
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#

#配置50x页面
error_page 500 502 503 504 /50x.html;

#精确匹配
location = /50x.html {
root html;
}

#后缀是.php时全部转发到apache服务器
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

#后缀是.php时全部转发到FastCGI服务器
# 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;
# }
#}

}