#user nobody;
worker_processes 1;##工作线程数,一般和cpu的核数相同:可通过ps -ef | nginx查看线程数
#配置错误日志位置
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#nginx采用epoll模型
events {
#每个worker线程的连接数
#worker_processes*worker_connections为nginx支持的最大连接数,nginx官方说能支持5万连接,加入worker_processes为n。那么该值可配置5w/n
#该值还和系统能支持的最大可打开的文件数有关,可通过ulimit -a查看open files的值
#可以通过ulimit -SHn 10000 命令设置linux支持的最大打开文件数
#根据上面的两个值对该值进行合理的配置
worker_connections 1024;
}
# load modules compiled as Dynamic Shared Object (DSO)
#
#dso {
# load ngx_http_fastcgi_module.so;
# load ngx_http_rewrite_module.so;
#}
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"‘;
#使用日志格式输出一个日志(可以根据这个属性将nginx做日志采集器而不用作webserver)
#access_log logs/access.log main;
#用户态设置为on表示启动高效传输文件的模式。sendfile可以让Nginx在传输文件时直接在磁盘和tcp socket之间传输数据。
#如果这个参数不开启,会先在用户空间(Nginx进程空间)申请一个buffer,用read函数把数据从磁盘读到cache,
#再从cache读取到用户空间的buffer,再用write函数把数据从用户空间的buffer写入到内核的buffer,最后到tcp socket。
#开启这个参数后可以让数据不用经过用户buffer。
sendfile on;
#tcp_nopush on;
#保持超时的时间
#keepalive_timeout 0;
keepalive_timeout 65;
#压缩,如果打开,会把返回的内容进行压缩。会增加服务器的损耗,但是换来了带宽。如果传输的都是小文件,没有必要开
#gzip on;
#定义一组服务器,配合反向代理实现负载均衡,此时keepalive_timeout应该设置为0
#upstream name {
#server ip:port
#server ip:port
#}
#虚拟服务器。可以虚拟一台服务器。并允许多台虚拟服务器对应一个端口,多台虚拟server之间通过server_name区分
#nginx根据ip、port和hosts决定server
server {
listen 80; #监听的端口号
server_name localhost; #虚拟服务器的名称
#charset koi8-r;
#access_log logs/host.access.log main;
#对location配置不同的uri,可以分为不同的模块
#logs目录下的access.log文件中记录了请求的uri
#location的uri配置参考http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#location
location / { #访问的路径
root html; #访问的根目录,该目录是相对目录,相对于nginx的安装目录
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; ##反向代理,将请求发送给后面配置的地址。可以结合upstream做基于反向代理的负载均衡
#}
# 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;
#}
}
}
原文:https://www.cnblogs.com/zhangyongJava/p/10833696.html