nginx配置文件nginx.conf详解
来源:互联网 发布:java web权限管理框架 编辑:程序博客网 时间:2024/06/16 03:09
#user nobody;worker_processes 1;#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;}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"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; 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; } # 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; # } #}}
worker_processes
启动进程的数目,通常和cpu数目一致
error_log
全局错误日志
events{
use epoll;
worker_connections 1024;
}
events中配置工作模式以及连接数上限。
epoll是多路复用io中的一种方式,可以提高nginx性能;
worker_connections 就是单个启动进程worker_process最大并发链接数
并发总数 = worker_processes * worker_connections
http {
include mime.types;
default_type application/octet-stream;
设置mime类型,由mime.type定义,默认类型application/octet-stream
mime.type设置http响应的Content_Type
#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;
记录详细日志信息,logs/access.log是日志具体的存储位置
sendfile on;
设置nginx是否调用sendfile()方法输出文件(对于下载或者磁盘重负载的应用可以设置为off,来平衡磁盘和I/O处理速度)
#tcp_nopush on;
nginx在一个数据包中发送所有头文件,而不需要一个一个发送
#tcp_nodelay on;
设置nginx不要缓存数据
#keepalive_timeout 0;
keepalive_timeout 65;
设置连接超时时间
#gzip on;
开启压缩(gzip格式)
server {
listen 80;
监听端口,80是默认端口
server_name localhost;
定义使用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;
}
定义错误页面
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1; 配置proxy_pass代理转发
#}
# 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服务器监听端口与地址
# 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;
# }
#}
}
upstream name{
server ip1:port weight = 1;
server ip2:port weight = 2;
server ip3:port weight = 3;
}
upstream 实现负载均衡,以weight(权重)方式分发,权重越大被分配到的几率越大
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
设置请求缓存,client_header_buffer_size是请求头缓冲区,超过了就会使用large_client_header_buffers
- Nginx配置文件nginx.conf详解
- Nginx 配置文件nginx.conf 详解
- NGINX配置文件nginx.conf详解
- nginx配置文件nginx.conf详解
- Nginx配置文件nginx.conf详解
- Nginx配置文件详解(nginx.conf)
- Nginx配置文件nginx.conf详解
- Nginx配置文件nginx.conf详解
- Nginx nginx.conf配置文件详解
- Nginx 配置文件 nginx.conf 详解
- Nginx配置文件nginx.conf详解
- Nginx 配置文件 nginx.conf 详解
- Nginx 配置文件 nginx.conf 详解
- Nginx配置文件nginx.conf详解
- Nginx配置文件nginx.conf详解
- Nginx 配置文件 nginx.conf 详解
- Nginx配置文件nginx.conf详解
- Nginx 配置文件 nginx.conf 详解
- Activity横屏显示
- 【十八掌●武功篇】第十六掌:Spark之Scala语法快速概览
- 查询字段相同的值
- Linux中使用Shell脚本插入mysql数据库中文字段值乱码问题
- 达内课程-File用法(上)
- nginx配置文件nginx.conf详解
- 自定义view 绘制太极案例
- 铺地毯
- Qt5.3.1+opencv2.4.8中运行程序出现错误----未找到文件:collect2.exe
- Ubuntu16.04+Cuda8.0(gtx1060)+Cudnn5.1+OpenCV2.4.13+anaconda2+caffe详细配置
- 七周第五次课 2017.12.1 iptables规则备份和恢复、firewalld的9个zone、firewalld关于zone的操作、firewalld关于service的操作
- 为什么现在机器学习如此火爆
- Hibernate的学习之路九(主键的生成策略)
- SQLiteOpenHelper 文件路径