|NO.Z.00068|——————————|LinuxNetwork|——|Linux&Nginx&反向代理.V04|——|Nginx.conf详解|
一、nginx.conf配置文件详解
### --- nginx.conf配置文件详解
[root@server11 ~]# vim /usr/local/nginx/conf/nginx.conf
user www www;
#程序运行用户和组
worker_processes auto;
#启动进程,指定nginx启动的工作进程数量,建议按照CPU数量来指定,一般等于CPU核心数目
error_log /home/wwwlogs/nginx_error.log crit;
#全局错误日志
pid /usr/local/nginx/logs/nginx.pid;
#主进程PID保存文件
worker_rlimit_nofile 51200;
#文件描述符数量
events
{
use epoll;
#使用epoll模型,对于2.6以上的内核,建议使用epoll模型以提高性能。
worker_connections 51200;
#工作进程的最大连接数量,根据硬件调整,和前面工作进程配置起来用,尽量大,但是别把CPU跑到100%就行每个进程允许的最大连接数,理论行每台nginx服务器的最大连接数为worker_processes*worker_connections,具体还要看服务器的硬件、宽带等。
}
http
#整体环境配置-网站配置
{
include mime.types;
default_type application/octet-stream;
#设定mime类型,文件传递类型由mime.type文件定义
server_names_hash_bucker_size 128;
#保存服务器名字的hash表大小
client_header_buffer_size 32k;
#客户端请求头部缓冲区大小
large_client_header_buffers 4 32k;
#最大客户端头缓冲大小
client_max_body_size 50m;
#客户端最大上传文件大小(M)
sendfile on;
#sendfile指定指定nginx是否调用sendfile函数来输出文件,对于普通应用,必须设为on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
tcp_nopush on;
#这个是默认的,结果就是数据包不会马上传送出去,等到数据包最大时,一次性的传输出去,这样有助于解决网络堵塞,(只在sendfile on时有效)
keepalive_timeout 60;
#连接超时时间
tcp_nodelay on
#禁止nagle算法,也既不缓存数据,有效解决网络阻塞
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64K;
fastcfi_busy_buffers_size 128k;
fastcfi_temp_file_write_size 256l;
#fastcfi设置
gzip on;
gzip_min_length 1k;
gzip_buffers 416k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_tupes text/plain application/javascrpt application/x-javascript text/javascript text/css application/xml application xml+rss;
gzip_vary on;
gzip_proxied expired no_cache no_store private auth;
gzip_disable "MSIE[1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
#If enable limit_conn_zone,add"limit_conn perip 10;" to server section.
server_tokens off;
#隐藏nginx版本号(curl -I 192.。168.4.154可以查看,更加安全)
#log format
log_format access "$remote_addr -$remote_user [$time_local]"$request""
'$status $body_bytes_sent "$http_referer"'
""$http_user_agent"$http_x_forwarded_for';
#定义日志格式
server
{
listen 80 default_server;
#listen[::]:80 default_server ipb6only=on;
#监听80端口,web服务器的监听设置,可以采用“IP地址:端口"形式
server_name www.lnmp.org lnmp.org;
#服务器名,可以写多个域名,用空格分隔
index index.html index.htm index.php;
#默认网页文件
root /home/wwwroot/default;
#网页主目录
#error_page 404 /404.html;
include enable-php.conf;
location /nginx_status
{
sub_status on;
access_log off;
#开启status状态监测
location ~.*\(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
#静态文件处理,保存期30天;
location~.*\(js|css)?$
{
expires 12h;
}
#js和css文件处理,保存期为12小时
location~^
{
deny all;
}
access_log /home/wwwlogs/access.log access;
#正确访问日志
include vhost/*.conf;
#vhost/xia 子配置文件生效
}
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
分类:
cdv007-network
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通