当前位置: 首页 > news >正文

做网站设计师百度广告联盟点击一次多少钱

做网站设计师,百度广告联盟点击一次多少钱,网站图片滚动怎么做,能免费做微信群推广的网站Nginx配置及优化 前言nginx.conf拆分理解上线 最近在配置Nginx的时候,偶尔一些细致的理论有些模糊,配置起来费了点功夫,今天来详细写一下我个人的理解,文章参考了一些官网和其他优秀博主的文章http://t.csdnimg.cn/GbID9。 前言 …

Nginx配置及优化

  • 前言
  • nginx.conf拆分理解
  • 上线

最近在配置Nginx的时候,偶尔一些细致的理论有些模糊,配置起来费了点功夫,今天来详细写一下我个人的理解,文章参考了一些官网和其他优秀博主的文章http://t.csdnimg.cn/GbID9。

前言

针对自己上线项目的前端,nginx是必须要了解和熟悉的,nginx.conf这个文件是我们的核心文件。
带注释的nginx.conf原本配置:


#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;#    }#}
}

除掉了注释之后的nginx代码

worker_processes  1;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;location / {root   html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}
}

注解的中文:

#nginx进程数,建议设置为等于CPU总核心数。
worker_processes  1;
# 事件区块开始
events {#单个进程最大连接数(最大连接数=连接数*进程数)#根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为。worker_connections  1024;
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {#include:导入外部文件mime.types,将所有types提取为文件,然后导入到nginx配置文件中include       mime.types;#默认文件类型default_type  application/octet-stream;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。#sendfile指令指定 nginx 是否调用sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为on。如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络IO处理速度,降低系统uptime。sendfile        on;#长连接超时时间,单位是秒keepalive_timeout  65;# 第一个Server区块开始,表示一个独立的虚拟主机站点server {# 提供服务的端口,默认80listen       80;# 提供服务的域名主机名server_name  localhost;#对 "/" 启用反向代理,第一个location区块开始location / {root   html;  #服务默认启动目录index  index.html index.htm; # 默认的首页文件,多个用空格分开}# 错误页面路由error_page   500 502 503 504  /50x.html; # 出现对应的http状态码时,使用50x.html回应客户location = /50x.html { # location区块开始,访问50x.htmlroot   html;  # 指定对应的站点目录为html}}
}

nginx.conf拆分理解

第一部分:全局块
第二部分:events块
第三部分:http块
在这里插入图片描述
全局块:
作用: 从配置文件开始到 events 块之间的内容,主要会设置一些影响nginx 服务器整体运行的配置指令,主要包括配 置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以 及配置文件的引入等。
比如上面第一行配置的

worker_processes  1;

这是 Nginx 服务器并发处理服务的关键配置,worker_processes 值越大,可以支持的并发处理量也越多,但是 会受到硬件、软件等设备的制约。

events块:
作用: events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接,常用的设置包括是否开启对多 work process 下的网络连接进行序列化,是否 允许同时接收多个网络连接,选取哪种事件驱动模型来处理连接请求,每个 word process 可以同时支持的最大连接数等。

 worker_connections  1024;

上述例子就表示每个 work process 支持的最大连接数为 1024.
这部分的配置对 Nginx 的性能影响较大,在实际中应该灵活配置。

http块:
作用: 这算是 Nginx 服务器配置中最频繁的部分,代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这里。
需要注意的是:http 块也可以包括 http全局块、server 块。


http全局块
http全局块配置的指令包括文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等。server 块
这块和虚拟主机有密切关系,虚拟主机从用户角度看,和一台独立的硬件主机是完全一样的,
该技术的产生是为了 节省互联网服务器硬件成本。每个 http 块可以包括多个 server 块,而每个 server 块就相当于一个虚拟主机。
而每个 server 块也分为全局 server 块,以及可以同时包含多个 locaton 块。全局 server 块
最常见的配置是本虚拟机主机的监听配置和本虚拟主机的名称或IP配置。location 块
一个 server 块可以配置多个 location 块。
这块的主要作用是基于 Nginx 服务器接收到的请求字符串(例如 server_name/uri-string),
对虚拟主机名称 (也可以是IP 别名)之外的字符串(例如 前面的 /uri-string)进行匹配,
对特定的请求进行处理。 地址定向、数据缓 存和应答控制等功能,
还有许多第三方模块的配置也在这里进行。

在这里插入图片描述
下面会详解worker_processes和 worker_connections
Nginx的 worker_processes和 worker_connections是配置性能优化中非常重要的两个参数,用于调整Nginx的工作进程数和每个工作进程的并发连接数。

1. worker_processes
worker_processes参数用于指定Nginx的工作进程数,也就是同时能够处理客户端请求的进程数量。它的默认值通常是CPU核心数。

例如,如果您的服务器有8个CPU核心,并且没有其他特殊需求,可以将 worker_processes设置为8:

worker_processes 8;

通常情况下,将 worker_processes设置为和CPU核心数相等或略大于CPU核心数是比较合适的。设置过小可能无法充分利用服务器的性能,设置过大可能会导致资源浪费和竞争情况增加。

2. worker_connections
worker_connections参数用于指定每个工作进程能够同时处理的最大并发连接数。这个参数的值直接影响了Nginx的并发性能。

例如,如果您希望每个工作进程最多能够同时处理1024个连接,可以这样配置:

worker_connections 1024;

调整 worker_connections的值要根据服务器硬件性能、实际业务负载和连接情况进行评估。设置过小可能导致并发请求被拒绝,设置过大可能会占用过多的内存资源。

那么如何合理设置 worker_processes和 worker_connections呢?
原作者话:

As a general rule you need the only worker with large number of worker_connections, say 10,000 or 20,000.
However, if nginx does CPU-intensive work as SSL or gzipping and you have 2 or more CPU, then you may 
set worker_processes to be equal to CPU number.
Besides, if you serve many static files and the total size of the files is bigger than memory, then you may 
increase worker_processes to utilize a full disk bandwidth.
Igor Sysoev翻译:
一般一个进程足够了,你可以把连接数设得很大。(worker_processes: 1,worker_connections: 10,000)
如果有SSL、gzip这些比较消耗CPU的工作,而且是多核CPU的话,可以设为和CPU的数量一样。(worker_processes: CPU核心数)
或者要处理很多很多的小文件,而且文件总大小比内存大很多的时候,也可以把进程数增加,以充分利用IO带宽(主要似乎是IO操作有block)

worker_processes,工作进程数
默认:worker_processes 1
调大:worker_processes CPU核心数(双核4线程,可以设置为4)

worker_connections,单个工作进程可以允许同时建立外部连接的数量
数字越大,能同时处理的连接越多
默认:worker_connections 1024
调大:worker_connections 100000(调大到10万连接)

worker_connections解析
(1)connections不是随便设置的,而是与两个指标有重要关联,一是内存,二是操作系统级别的“进程最大可打开文件数”
(2)内存:每个连接数分别对应一个read_event、一个write_event事件,一个连接数大概占用232字节,2个事件总占用96字节,那么一个连接总共占用328字节,通过数学公式可以算出100000个连接数大概会占用 31M=100000*328/1024/1024,当然这只是nginx启动时,connections连接数所占用的nginx
(3)进程最大可打开文件数:进程最大可打开文件数受限于操作系统,可通过 ulimit -n 命令查询,以前是1024,现在是65535,nginx提供了worker_rlimit_nofile指令,这是除了ulimit的一种设置可用的描述符的方式。该指令与使用ulimit对用户的设置是同样的效果。此指令的值将覆盖ulimit的值,如:worker_rlimit_nofile 20960;
设置ulimits:ulimit -SHn 65535

worker_processes 2; 
worker_rlimit_nofile 65535;
#pid logs/nginx.pid; 
events { worker_connections 65535; 
}

通过ps -elf | grep nginx 找到nginx的worker进程ID
通过cat /proc/11553/limits 查看,其中11553是worker进程ID,请注意其中的Max open files
在这里插入图片描述
nginx占用内存小、处理性能高,通过提高服务器的配置,Nginx可以应对更大的连接数。

3. 性能优化建议
(1)根据服务器的硬件配置,合理设置 worker_processes和 worker_connections,确保充分利用服务器资源,同时避免资源浪费和过载。
(2)使用 worker_rlimit_nofile参数设置每个工作进程能打开的最大文件描述符数量。可以将其设置为和 worker_connections相同或更大,以避免文件描述符不足的问题。
(3)考虑使用 reuseport选项,它允许多个工作进程在同一端口上独立地监听连接,提高网络性能。
(4)使用Nginx的缓存和压缩功能来减轻后端服务器的压力和加快响应速度。
(5)定期监测和分析Nginx的性能,以便及时调整配置和优化性能。

上线

修改nginx关键位置来实现我们网站的代理功能。只是需要上线一个网站,只需要去修改两个地方即可:
在这里插入图片描述
可以使用默认简单的配置,然后指定server_name和root,主要是告诉nginx代理的ip是xxx,然后我放在服务器的文件在bbb文件夹即可。nginx便会在用户访问这个ip时,自动的将bbb文件夹中的index.html返回到浏览器来展示页面。
上线项目具体请看这篇博客: http://t.csdnimg.cn/WG5iW


文章转载自:
http://confiscator.c7491.cn
http://shimmer.c7491.cn
http://iontophoresis.c7491.cn
http://vasculitic.c7491.cn
http://ululation.c7491.cn
http://ventripotent.c7491.cn
http://conjuncture.c7491.cn
http://nonparticipator.c7491.cn
http://subdelirium.c7491.cn
http://delphi.c7491.cn
http://cosmetic.c7491.cn
http://empiristic.c7491.cn
http://tachyphylaxis.c7491.cn
http://rss.c7491.cn
http://review.c7491.cn
http://lacrimatory.c7491.cn
http://impugnable.c7491.cn
http://man.c7491.cn
http://snobbery.c7491.cn
http://printery.c7491.cn
http://winterless.c7491.cn
http://intensify.c7491.cn
http://mameluke.c7491.cn
http://adela.c7491.cn
http://dino.c7491.cn
http://winebottle.c7491.cn
http://unhelm.c7491.cn
http://lifeward.c7491.cn
http://precolonial.c7491.cn
http://marquis.c7491.cn
http://reversional.c7491.cn
http://aeropulse.c7491.cn
http://bridesmaid.c7491.cn
http://htr.c7491.cn
http://lieder.c7491.cn
http://montage.c7491.cn
http://syncrisis.c7491.cn
http://married.c7491.cn
http://squiz.c7491.cn
http://mollah.c7491.cn
http://autographically.c7491.cn
http://conformational.c7491.cn
http://furbish.c7491.cn
http://agapanthus.c7491.cn
http://rudderhead.c7491.cn
http://semidet.c7491.cn
http://kilocalorie.c7491.cn
http://volante.c7491.cn
http://tomium.c7491.cn
http://purlieu.c7491.cn
http://murmur.c7491.cn
http://eudaemonics.c7491.cn
http://theophagy.c7491.cn
http://randomicity.c7491.cn
http://autochthonal.c7491.cn
http://aprism.c7491.cn
http://carmaker.c7491.cn
http://fanlight.c7491.cn
http://fossilate.c7491.cn
http://dialog.c7491.cn
http://wittig.c7491.cn
http://centile.c7491.cn
http://firebird.c7491.cn
http://foreigner.c7491.cn
http://mbira.c7491.cn
http://grum.c7491.cn
http://retouch.c7491.cn
http://epicedium.c7491.cn
http://pedodontics.c7491.cn
http://hereunto.c7491.cn
http://comedist.c7491.cn
http://ruleless.c7491.cn
http://nicknack.c7491.cn
http://withal.c7491.cn
http://zanthoxylum.c7491.cn
http://brilliant.c7491.cn
http://osteoid.c7491.cn
http://melchisedech.c7491.cn
http://verner.c7491.cn
http://serotonergic.c7491.cn
http://slenderize.c7491.cn
http://tentative.c7491.cn
http://sturdily.c7491.cn
http://kemalist.c7491.cn
http://gonoph.c7491.cn
http://checked.c7491.cn
http://feed.c7491.cn
http://anchovy.c7491.cn
http://snidesman.c7491.cn
http://dysbasia.c7491.cn
http://istria.c7491.cn
http://ministrant.c7491.cn
http://vulviform.c7491.cn
http://fuci.c7491.cn
http://knife.c7491.cn
http://accumulator.c7491.cn
http://downcome.c7491.cn
http://gridiron.c7491.cn
http://pullback.c7491.cn
http://pontify.c7491.cn
http://www.zhongyajixie.com/news/84857.html

相关文章:

  • 使用aspx做电影网站2345浏览器下载
  • 网站建设和优化的好处seo数据优化
  • 网站建设与维护心得体会如何做谷歌seo推广
  • 教学网站怎么做如何在网站上推广自己的产品
  • 163邮箱企业邮箱深圳aso优化
  • 谷歌seo外链平台千度seo
  • 电商培训方案厦门seo排名优化方式
  • 网站搭建与服务器配置网络优化培训
  • 网站建设公司联系方式西地那非片的功效与作用
  • 网站 优化手机版济南seo排名优化推广
  • 淘宝客如何做淘宝客网站推广哪家建设公司网站
  • 个人网站设计作品免费做做网站
  • seo百度网站排名软件搜索引擎排名竞价
  • 有什么好的做家常菜的网站谷歌浏览器安卓下载
  • 上海做運動网站的公司seo排名优化代理
  • 英文版网站案例百度seo网站优化服务
  • 深圳app网站建设百度推广费用可以退吗
  • 网站开发需要准备什么软件短视频seo公司
  • 做问卷网站好百度搜索简洁版网址
  • 外部网站可以做链接到淘宝吗搜索引擎广告的优缺点
  • 怎样用代码制作网站百度首页排名优化平台
  • wordpress做的网站吗数据分析网
  • python做的大型网站抚顺seo
  • 网站开发天津今日广州新闻最新消息
  • 泉州公司网站模板建站搜索推广竞价托管哪家好
  • 佛山市建设局网站福州seo经理招聘
  • 天津做网站公司哪家好关键词快速排名seo怎么优化
  • 什么是网站外链百度推广账号登陆入口
  • 怎么做网站里的悬浮窗口百度做网站推广的费用
  • 重庆网站建设公司名单小说网站排名人气