关注分享主机优惠活动
国内外VPS云服务器

NGX平滑升级及nginx配置文件详解

Ngx平滑升级和nginx配置文件

Nginx平滑升级,增加新功能。1.先获取老版本的编译信息。

2.获取新版本安装包和功能包。

3.配置新版本或功能,添加旧版本的编译参数,然后添加新的功能模块。

4.编译,编译后不要安装。

5.备份旧版本的程序,使用复制方法。停止老版本程序的进程后,将新版本程序复制到老版本程序的位置,直接替换老版本程序,启动新版本程序。

//查看旧版本的编译信息[root @ nginx ~]# nginx -vnginx version:nginx/1 . 20 . 2由GCC 8.5.0 2021 05 14(红帽8.5.0-4) (GCC)用OpenSSL 1.1.1k构建FIPS 2021年3月25日TLS SNI支持enabledconfigure参数:--前缀=/usr/local/nginx --user = nginx --group = nginx - git克隆https://gitee . com/ther -own/nginx _ module _ echo . git[root @ nginx ~]# Ls cond a-ks . cfgnginx -1 . 20 . 2 . tar . gznginx -1 . 22 . 0 . tar . gznginx -1 . 22 . 0 . 0 . tar . gznginx _ module _ echo//解压并编译[root @ nginx tar xf nginnx -1 . 22 . 0 . tar . gz[root @ nginnx ~]# /configure \ --prefix =/usr/local/nginx \ --user = nginx \ --group = nginx \ --with -debug \ --with -http _ SSL _ module \ -http _ realip _ module \ --with -http _ image _ filter _ module \ --with -http _ gunzip _ module \ ----with -http _ gzip _ static _ module \ -4../NGINX _ module _ echo//添加新函数使用-add-module =模块目录位置[root @ nginxnginx -1 . 22 . 0]# make[root @ nginxnginx -1 . 22 . 0]# ls changes . ru LICENSE Makefile README auto conf configure contrib html man objs src[root @ NGINX -1 . 22 . 0]# objs/ng x-VNGINXVersion:NGINX/1 . 22 . 0[root @ nginxnginx -1.22\cp。/objs/nginx/usr/local/nginx/sbin/nginx;system CTL start nginx[root @ nginx nginx -1 . 22 . 0]# nginx -vnginx版本:nginx/1 . 22 . 0[root @ nginx nginx -1 . 22 . 0]# ss -anltState rec v-Q send -Q本地地址:端口对等地址:端口进程列表EN 0 128 0.0 . 0.0:80 0 0 . 0 . 0 . 0:*列表EN 0 128 0.0 . 0.0:22 0 . 0 . 0:*列表EN 0 128[:]:22[:]

nginx的主配置文件:/usr/local/nginx/conf/nginx.conf默认启动nginx时,使用的配置文件是:安装路径/conf/nginx . conf文件。启动nginx时可以指定-c选项读取的配置文件。nginx的常用配置文件及其功能。

nginx . conf ginx mime . types mime类型关联扩展文件fastcgi.conf fastcgi相关配置proxy.conf代理相关配置sites.conf配置nginx提供的网站,包括虚拟主机

nginx.conf的详细配置nginx.conf的内容分为以下几段:

主配置段:全局配置段。主配置部分可能包含事件配置部分event {}:定义事件模型http {}的工作特性:定义与http协议相关的配置说明:以分号结束,语法格式如下:derective value1 [value2...];使用支持变量:内置变量:模块会提供内置变量来定义自定义变量:设置var_name值。

用于调试和查找问题的配置参数守护程序{ on | off };//是否将nginx作为守护进程运行,调试时应设置为off master _ process { on | off };//是否在master/worker模型下运行nginx,可以在调试时设置为offerror_log位置级别;//配置错误日志error_log中的位置和级别可以有以下选项:位置级别文件stderr syslog: server = address [,parameter = value]memory:size debug:要使用调试级别,需要使用& ndash编译nginx时。带-调试选项信息通知警告错误关键警报紧急情况

用户用户名[组名],正常操作所必需的配置参数;//指定运行工作进程的用户和组PID/path/to/PID _ file;//指定nginx守护进程的pid文件worker_rlimit_nofile号;//设置所有工作进程可以打开的最大文件数。默认值为1024worker _ rlimit _ core size//指明所有工作进程可以使用的最大总核心文件大小,保持默认值即可。

优化配置参数worker _ processes n;//启动n个工作进程,其中n通常设置为cpu核心总数-1或等于核心总数worker_cpu_affinity cpumask以避免上下文切换...;//将进程绑定到cpu,以避免频繁刷新缓存。//cpumask:用8位二进制表示cpu核,例如:0000001//第一个cpu核000010//第二个cpu核0000100//第三个cpu核0000 1000 //第四个cpu核0001 0000 //第五个cpu核0010 0000 //第六个cpu核0100 0000 //第七个cpu核100 0000 //第八个cpu核timer _ resolution interval//计时器分辨率。降低该值可以减少gettimeofday()系统调用worker_priority number的次数;//表示worker process 6.5事件相关配置的nice值:event{}节中的配置参数accept _ mutex { off | on };//当调度用户对每个工作进程的请求时,//主机使用的负载平衡锁;On意味着多个worker可以依次响应新的请求并串行地锁定_file文件;//accept_mutex使用的互斥文件路径是use[epoll | rt SIG | select | poll];//指示使用的事件模型。建议让nginx自己选择worker _ connections #;//每个进程可以接受的最大连接数

网络相关配置参数keepalive_timeout号;//长连接的超时时长,默认为65skeepalive_requests数;//允许在长连接上请求的最大资源数keepalive _ disable[msie 6 | Safari | none];//为指定类型的UserAgent禁用长连接tcp _ nodelay on | off//是否对长连接使用TCP_NODELAY选项。为了提高用户体验,通常设置为onclient _ header _ timeout number//读取http请求报文头的超时周期client_body_timeout号;//读取http请求消息正文部分的超时周期send_timeout号;//发送响应消息的超时时间

fastcgi LNMP:php启用fpm模型配置示例的相关配置参数如下:

位置~ \。php $ { root htmlfastcgi _ pass 127 . 0 . 0 . 1:9000;//定义反向代理fastcgi _ index index.php;fastcgi _ param SCRIPT _ FILENAME/scripts $ fastcgi _ SCRIPT _ name;包括fastcgi _ params}

nginx作为web服务器使用的配置:配置参数http { & helliphttp { } segment }的:配置http关联,由ngx_http_core_module模块引入。nginx的HTTP配置主要包括四个块,结构如下:

Http {//协议级别includedmime.typesdefault_type应用程序/octet -流;keepalive _ timeout 65gzip打开;上游{//负载平衡配置...} server {//服务器级别,每个服务器都类似于httpd中的一个

Http{}段配置指令:server {}:定义一个虚拟主机,示例如下:server { listen 80服务器名www.idfsoft.com;root "/vhosts/web ";}监听:指定监听的地址和端口:监听地址[:端口];监听端口;服务器名称名称[...];它后面可以跟多个主机,名称可以使用正则表达式或通配符。当有多个服务器时,匹配顺序如下:

首先,在左边的通配符匹配检查上做精确匹配检查,比如*.idfsoft.com在右边的通配符匹配检查上,比如mail。*正则表达式匹配检查,如~。*.idfsoft.com $ default _ server root path;设置资源路径映射,用于指示请求的URL对应的资源在文件系统上的起始路径。

别名路径;用于位置配置段以定义路径别名。

索引文件;默认页面索引index.php·index.html;

错误_页面代码[& hellip;] [=code] URI | @name表示根据http响应状态码的特殊错误页面,如error _ page 404/404 _ customized.html。

[=code]:使用指定的响应代码而不是默认的原始响应进行响应。默认值表示新资源的响应代码是其响应代码,例如,error _ page 404 = 200/404 _ customized.html。

log_format定义日志格式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;//注意:格式名main可以自己定义,但是要一对一。另外,这里可用的变量是nginx各个模块内置的变量location部分,通过指定模式可以匹配客户端请求的URI。//功能:允许根据用户请求的URI匹配定义的位置。当匹配时,该请求将由相应位置配置块中的配置来处理。比如做门禁之类的功能。//语法:location [modifier] pattern {......}常用修饰符描述:修饰符函数=精确匹配~正则表达式模式匹配,区分大小写~ *正则表达式模式匹配,不区分大小写前缀匹配,类似于没有修饰符的行为,也是从指定的模块开始。不同的是,如果模式匹配,那么停止搜索其他模式。不支持命名位置部分的正则表达式@ definition。这些部分不能被客户端访问,只能被内部生成的请求访问,如try_files或error_page。搜索顺序和优先级:从最高到最低是

与=的精确匹配优先于那些带有~修饰符的匹配,以及那些在匹配正则表达式的开头带有或*修饰符的匹配(按照它们在配置文件中定义的顺序)。如果正则表达式匹配URI,则不使用修饰符的精确匹配的优先级如下:

(location = path)-->:(location ^~路径)-->:(location ~ regular)-->:(location ~ * regular)-->:(location path)//如果没有添加修饰符,则按照[root @ localhost conf]# vimnginx . conf//的顺序添加三个访问页面测试location/{ echo ' haha;}地点/西溪{ echo西溪’;}地点/呵呵{ echo呵呵’;}[root @ localhost conf]# system CTL restart nginx . service[root @ localhost conf]# curl 192 . 168 . 111 . 141哈哈[root @ localhost conf]# curl 192 . 168 . 111 . 141/xixixi[root @ localhost conf]# curl 192 . 168 . 111 . 141/hehe/=完全匹配[root @ localhost conf]# vimnginx . conf location/{ echo '哈哈;}地点/西溪{ echo西溪’;} location =/Xixi { echo‘呵呵’;}[root @ localhost conf]# systemctlrestartnginx.service//You可以看到两个目录是一样的,但是=优先级大于没有=的,所以是呵呵[root @ localhost conf]# curl 192 . 168 . 111 . 141/Xixi he//Add ~要区分大小写[root @ localhost conf]# vimnginx . conf location/{ echo '哈哈';}地点/西溪{ echo西溪’;}地点~/西溪{ echo呵呵’;}[root @ localhostconf]# systemctlrestartnginx.service//The输出默认为哈哈[root @ localhostconf]# curl 192 . 168 . 111 . 141/Xihaha[root @ localhost conf]# curl 192 . 168 . 111 . 141/Xixihehe/~ *不区分大小写[root @ localhost conf]# vimnginx . conf location/{ echo ' haha];}地点/西溪{ echo西溪’;}地点~ */西溪{ echo呵呵’;}[root @ localhostconf]# systemctlrestartnginx.service//Both西西和西西可以访问呵呵[root @ localhostconf]# curl 192 . 168 . 111 . 141/Xi Hehe[root @ localhost conf]# curl 192 . 168 . 111 . 141/XIXI Hehe/~匹配前缀[root @ localhost conf]# vimnginx . conf location/{ echo '哈哈';}地点^~/xixi {回声‘西溪’;}地点~/西溪{ echo呵呵’;[root @ localhostconf]# systemctlrestartnginx.service//prefix匹配如果资源被访问就停止搜索[root @ localhostconf]# curl 192 . 168 . 111 . 141/Xixixi在这里。这篇关于nginx平滑升级nginx配置文件的文章就介绍到这里。关于nginx平滑升级的更多信息,请搜索主机频道zhujipindao之前的文章。或者继续浏览下面的相关文章。希望大家支持主机频道zhujipindao。以后多来com!

未经允许不得转载:主机频道 » NGX平滑升级及nginx配置文件详解

相关推荐

评论 抢沙发

评论前必须登录!