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

国外商品网站网站客服

国外商品网站,网站客服,成都个人做网站,做视频链接的网站Nginx网络服务——主配置文件-nginx.conf 一、全局配置的六个模块简介二、nginx配置文件的详解1.全局配置模块2.I/O 事件配置3.HTTP 配置4.Web 服务的监听配置5.其他设置 三、访问状态统计与控制1.访问状态统计2.基于授权的访问控制3.基于客户端的访问控制 一、全局配置的六个模…

Nginx网络服务——主配置文件-nginx.conf

  • 一、全局配置的六个模块简介
  • 二、nginx配置文件的详解
      • 1.全局配置模块
      • 2.I/O 事件配置
      • 3.HTTP 配置
      • 4.Web 服务的监听配置
      • 5.其他设置
  • 三、访问状态统计与控制
      • 1.访问状态统计
      • 2.基于授权的访问控制
      • 3.基于客户端的访问控制

一、全局配置的六个模块简介

模块说明
全局块全局配置,对全局生效
events块配置影响 Nginx 服务器与用户的网络连接
http块配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置
server块配置虚拟主机的相关参数,一个 http 块中可以有多个 server 块
location块用于配置匹配的 uri
upstream配置后端服务器具体地址,负载均衡配置不可或缺的部分

二、nginx配置文件的详解

vim /usr/local/nginx/conf/nginx.conf

1.全局配置模块

#user nobody; 					#运行用户,若编译时未指定则默认为 nobody
worker_processes 1; 			#工作进程数量,一般设置为和 CPU 核数一样;设置为auto,nginx将会自己获取这个数值
#error_log logs/error.log; 		#错误日志文件的位置
#pid logs/nginx.pid; 			#PID 文件的位置
worker_rlimit_nofile 60000;		#设置所有worker进程最大可以打开的文件数,默认为1024

在这里插入图片描述

2.I/O 事件配置

events {use epoll; 					#使用 epoll I/O模型,2.6及以上版本的系统内核,建议使用epoll模型以提高性能worker_connections 60000; 	#每个进程处理 60000 个连接multi_accept on;            #是否一次性将监听到的连接全接收进来,默认为off,关闭时一次接收一条连接accept_mutex on;            #默认为on,开启时表示以串行方式接入新连接,否则将通报给所有worker。这可能会浪费资源并产生不可预计的后果,例如惊群问题
}注:
如提高每个进程的连接数还需执行“ulimit -n 65535”命令临时修改本地每个进程可以同时打开的最大文件数。
在Linux平台上,在进行高并发TCP连接处理时,最高的并发数量都要受到系统对用户单一进程同时可打开文件数量的限制(这是因为系统为每个TCP连接都要创建一个socket句柄,每个socket句柄同时也是一个文件句柄)。
可使用ulimit -a命令查看系统允许当前用户进程打开的文件数限制。
epoll是Linux内核为处理大批句柄而作改进的poll,是Linux下多路复用IO接口select/poll的增强版本,它能显著的减少程序在大量并发连接中只有少量活跃的情况下的系统CPU利用率。
worker_processes的值和work_connections的值决定了最大并发数量,最大并发数计算方式为:worker_processes*worker_connections。但在反向代理场景中计算方法不同,因为nginx既要维持和客户端的连接,又要维持和后端服务器的连接,因此处理一次连接要占用2个连接,所以最大并发数计算方式为:worker_processes*worker_connections/2。

3.HTTP 配置

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;##只在sendfile on时有效。调用tcp_cork方法,让数据包不会马上传送出去,等到数据包最大时,一次性的传输出去,这样有助于解决网络堵塞。默认为off。#tcp_nopush     on;##连接保持超时时间,单位是秒#keepalive_timeout  0;keepalive_timeout  65;##gzip模块设置,设置是否开启gzip压缩输出#gzip  on;

4.Web 服务的监听配置

	server {##监听地址及端口listen 80; ##站点域名,可以有多个,用空格隔开server_name www.kgc.com;##网页的默认字符集charset utf-8;##根目录配置location / {##网站根目录的位置/usr/local/nginx/htmlroot html;##默认首页文件名index index.html index.php;}##内部错误的反馈页面error_page 500 502 503 504 /50x.html;##错误页面配置location = /50x.html {root html;}}
}

5.其他设置

日志格式设定:
$remote_addr$http_x_forwarded_for用以记录客户端的ip地址;
$remote_user:用来记录客户端用户名称;
$time_local: 用来记录访问时间与时区;
$request: 用来记录请求的url与http协议;
$status: 用来记录请求状态;成功是200,
$body_bytes_sent :记录发送给客户端文件主体内容大小;
$http_referer:用来记录从哪个页面链接访问过来的;
$http_user_agent:记录客户浏览器的相关信息;
通常web服务器放在反向代理的后面,这样就不能获取到客户的IP地址了,通过$remote_add拿到的IP地址是反向代理服务器的iP地址。反向代理服务器在转发请求的http头信息中,可以增加x_forwarded_for信息,用以记录原有客户端的IP地址和原来客户端的请求的服务器地址。location常见配置指令,root、alias、proxy_pass
root(根路径配置):root /var/www/html
请求www.kgc.com/test/1.html,会返回文件/var/www/html/test/1.htmlalias(别名配置):alias /var/www/html
请求www.kgc.com/test/1.html,会返回文件/var/www/html/1.htmlproxy_pass(反向代理配置)

三、访问状态统计与控制

1.访问状态统计

先使用命令/usr/local/nginx/sbin/nginx -V 查看已安装的 Nginx 是否包含 HTTP_STUB_STATUS 模块

cat /opt/nginx-1.12.0/auto/options | grep YES #可查看 nginx 已安装的所有模块
在这里插入图片描述

修改 nginx.conf 配置文件指定访问位置并添加 stub_status 配置

cd /usr/local/nginx/conf
cp nginx.conf nginx.conf.bak
vim /usr/local/nginx/conf/nginx.conf
......
http {
......server {listen 80;server_name www.ztm.com;charset utf-8;location / {root html;index index.html index.php;}##添加 stub_status 配置##location /status { 					#访问位置为/statusstub_status on; 				#打开状态统计功能access_log off; 				#关闭此位置的日志记录}}
}

在这里插入图片描述
重启服务,访问测试
systemctl restart nginx

浏览器访问 http://192.168.30.20/status
Active connections:表示当前的活动连接数,即当前与 Nginx 服务器建立的连接数。
server accepts handled requests :表示已经处理的连接信息
三个数字依次表示服务器已接收的连接数;服务器成功处理的连接数;服务器累计处理的总请求数(在保持连接模式下,请求数量可能会大于连接数量)
Reading:表示当前正在从客户端读取数据的连接数。
Writing:表示当前正在向客户端写入数据的连接数。
Waiting:表示当前空闲并等待请求的连接数。

可 curl -Ls http://192.168.30.20/status 结合 awk与if 语句进行性能监控。
在这里插入图片描述

2.基于授权的访问控制

生成用户密码认证文件

yum install -y httpd-tools
htpasswd -c /usr/local/nginx/passwd.db zhangsan
chown nginx /usr/local/nginx/passwd.db
chmod 400 /usr/local/nginx/passwd.db

在这里插入图片描述

修改主配置文件相对应目录,添加认证配置项

vim /usr/local/nginx/conf/nginx.conf
......server {location / {......##添加认证配置##auth_basic "secret";				#设置密码提示框文字信息auth_basic_user_file /usr/local/nginx/passwd.db;}}

在这里插入图片描述

重启服务,访问测试

nginx -t
systemctl restart nginx浏览器访问 http://192.168.30.20

在这里插入图片描述

3.基于客户端的访问控制

设置前的访问,其他主机访问测试
在这里插入图片描述

访问控制规则如下
deny IP/IP 段:拒绝某个 IP 或 IP 段的客户端访问。
allow IP/IP 段:允许某个 IP 或 IP 段的客户端访问。
规则从上往下执行,如匹配则停止,不再往下匹配。

vim /usr/local/nginx/conf/nginx.conf
......server {location / {......##添加控制规则##allow 192.168.30.10; 					#允许访问的客户端 IPdeny all;								#拒绝其它IP客户端访问}}systemctl restart nginx

在这里插入图片描述
设置后的访问测试:
在这里插入图片描述


文章转载自:
http://tammany.sLnz.cn
http://kinetics.sLnz.cn
http://misdone.sLnz.cn
http://affirmative.sLnz.cn
http://javabeans.sLnz.cn
http://triumphalist.sLnz.cn
http://unlax.sLnz.cn
http://fining.sLnz.cn
http://monitorial.sLnz.cn
http://piave.sLnz.cn
http://chemigraphically.sLnz.cn
http://chinchilla.sLnz.cn
http://machinator.sLnz.cn
http://bouillabaisse.sLnz.cn
http://duplicator.sLnz.cn
http://allegorize.sLnz.cn
http://foetal.sLnz.cn
http://budgeteering.sLnz.cn
http://hyperope.sLnz.cn
http://somaliland.sLnz.cn
http://irradiator.sLnz.cn
http://nippy.sLnz.cn
http://superactinide.sLnz.cn
http://momentum.sLnz.cn
http://braxy.sLnz.cn
http://radiotelescope.sLnz.cn
http://lurking.sLnz.cn
http://seeming.sLnz.cn
http://mastoidean.sLnz.cn
http://badman.sLnz.cn
http://substantialise.sLnz.cn
http://perfectability.sLnz.cn
http://rale.sLnz.cn
http://diaphoneme.sLnz.cn
http://theomorphic.sLnz.cn
http://rheophil.sLnz.cn
http://taky.sLnz.cn
http://ladefoged.sLnz.cn
http://diamondback.sLnz.cn
http://melolonthid.sLnz.cn
http://scream.sLnz.cn
http://punishment.sLnz.cn
http://turbogenerator.sLnz.cn
http://bordello.sLnz.cn
http://desuperheat.sLnz.cn
http://zapping.sLnz.cn
http://colorado.sLnz.cn
http://fermentive.sLnz.cn
http://grandisonian.sLnz.cn
http://brickkiln.sLnz.cn
http://cetaceous.sLnz.cn
http://strickle.sLnz.cn
http://nuclein.sLnz.cn
http://slaister.sLnz.cn
http://nadge.sLnz.cn
http://serfdom.sLnz.cn
http://malinger.sLnz.cn
http://hyphenate.sLnz.cn
http://kikongo.sLnz.cn
http://trichopathy.sLnz.cn
http://columbic.sLnz.cn
http://pluviose.sLnz.cn
http://serpasil.sLnz.cn
http://cermet.sLnz.cn
http://cloke.sLnz.cn
http://reproducing.sLnz.cn
http://crissum.sLnz.cn
http://zimbabwean.sLnz.cn
http://lukewarm.sLnz.cn
http://euhemerus.sLnz.cn
http://luluai.sLnz.cn
http://play.sLnz.cn
http://encrust.sLnz.cn
http://situp.sLnz.cn
http://contentious.sLnz.cn
http://scorper.sLnz.cn
http://sulphanilamide.sLnz.cn
http://heparinize.sLnz.cn
http://weazen.sLnz.cn
http://loudhailer.sLnz.cn
http://dogginess.sLnz.cn
http://syngarny.sLnz.cn
http://ulcer.sLnz.cn
http://ageratum.sLnz.cn
http://unfadingly.sLnz.cn
http://venae.sLnz.cn
http://increasedly.sLnz.cn
http://supernormal.sLnz.cn
http://exdividend.sLnz.cn
http://lore.sLnz.cn
http://nickeliferous.sLnz.cn
http://axonometric.sLnz.cn
http://incorruptibility.sLnz.cn
http://okey.sLnz.cn
http://monitress.sLnz.cn
http://chon.sLnz.cn
http://syngas.sLnz.cn
http://dogger.sLnz.cn
http://craniectomy.sLnz.cn
http://parvenu.sLnz.cn
http://www.hrbkazy.com/news/73175.html

相关文章:

  • 企业展厅建设的原则seo培训学什么
  • 做个自己的网站需要多少钱360优化大师app下载
  • wordpress目录只显示第一个图片抚州seo外包
  • 网站开发学生鉴定表深圳网络推广服务公司
  • 做网站运营跟专业有关吗企业网站模板 免费
  • 网站建设解决方网站开发教程
  • 网站免费空间免备案小红书seo
  • ui设计师是啥seo零基础教学视频
  • 夫妻做网站西安网络seo公司
  • 做白日梦的哪个网站站长素材音效网
  • wordpress页面侧边栏消失青岛seo培训
  • 深圳门户网站建设公司廊坊网站设计
  • 个人网站可以做资讯小说类镇江优化推广
  • web动态网页设计步骤整站快速排名优化
  • 海南最新通知今天重要消息优化精灵
  • 大兴西红门网站建设chatgpt 网站
  • 网站正在建设中 html5微信上如何投放广告
  • 家电网站设计方案东莞网络公司电话
  • 深圳制作网站的公司重庆百度竞价开户
  • 怎样做才能发布你的网站seo排名如何优化
  • 网站建设总结 优帮云百度推广助手
  • 关于地产设计网站品牌型网站设计推荐
  • 做a视频 免费网站南京 seo 价格
  • 做自己网站做站长培训机构专业
  • 高州网站建设公司网站制作的费用
  • 永康建设网站站长seo
  • 昆明双鼎网站制作江苏网站seo设计
  • 那个网站专门做幽默视频的百度搜索平台
  • 银川网站制作网页设计模板素材图片
  • 机械设备如何做网站微博营销策略