一、Nginx核心配置
Nginx配置文件组成部分
主配置文件/etc/nginx/nginx.conf子配置文件/etc/nginx/conf.d/*.conffastcgi, uwsgi,scgi 等协议相关的配置文件mime.types:支持的mime类型,/etc/nginx/mime.types,包含文本、图像、音频、视频以及其他应用程序专用的数据
二、/etc/nginx/nginx.conf主配置结构:大致分为四部分
1.全集配置段
###################################### #1.全集配置段 ###################################### #nginx启动用户/组 user nginx nginx; #启动工作进程数数量 worker_processes auto; #错误日志记录配置 error_log /var/log/nginx/error.log notice; #pid文件保存路径 pid /var/run/nginx.pid; #将Nginx工作进程绑定到指定的CPU核心 worker_cpu_affinity 0001 0010 0100 1000; #第0号---第3号CPU #前台运行Nginx服务用于测试、docker等环境 daemon off; #是否开启Nginx的master-worker工作模式,仅用于开发调试场景,默认为on master_process off|on; #高并发配置 worker_rlimit_nofile 100000;
2.事件驱动相关配置
###################################### #2.事件驱动相关配置 ###################################### events { #每个工作进程可以同时支持的最大连接数 worker_connections 1024; #使用epoll事件驱动,select、poll、epoll use epoll; #惊群:默认为off,新请求会唤醒所有worker进程, #on为同一时刻一个请求轮流由work进程处理,而防止唤醒所有worker accept_mutex on; #on时每个工作进程可以同时接受多个新的网络连接 multi_accept on; }
3.http/https协议相关配置
###################################### #3.http/https协议相关配置 ###################################### http { #支持的文件类型 include /etc/nginx/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 /var/log/nginx/access.log main; #自定义优化参数 sendfile on; #tcp_nopush on; #合并请求后统一发送给客户端,必须开启sendfile #为off时,延迟0.2s发送,默认On时,不延迟发送,立即发送用户响应报文 #tcp_nodelay off; #开启keepalived模式下是否启用该选项 #设置会话保持时间 keepalive_timeout 65; #开启文件压缩 #gzip on; server { #监听端口 listen 80; #设置server name server_name localhost; #设置编码格式,默认是俄语格式,改为utf-8 #charset utf-8; #access_log /var/log/nginx/host.access.log main; #是否在响应报文的Server首部显示nginx版本 server_tokens on | off | build | string; location / { root /usr/share/nginx; index index.html index.htm; } #location /mobile { # alias /opt/nginx/m; #} #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 /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 #以http的方式转发php请求到指定web服务器 #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 ##以fastcgi的方式转发php请求到php处理 #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 #拒绝web形式访问指定文件,通过.htaccess文件改变自己的重定向等功能 #location ~ /.ht { # deny all; #} } include /etc/nginx/conf.d/*.conf; }
4.默认配置文件不超过下面两个块
###################################### #4.默认配置文件不超过下面两个块 ###################################### #mail 协议相关配置段 mail { ... } #stream 服务器相关配置段 stream { ... }
在学习中进步,如有错误,请多多批评指正
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)