Nginx优化实战(进程管理、防盗链)
发表于:2024-09-23 作者:千家信息网编辑
千家信息网最后更新 2024年09月23日,Nginx进程管理实例:[root@nginx nginx-1.12.2]# cd /usr/local/nginx/[root@nginx nginx]# lsclient_body_temp f
千家信息网最后更新 2024年09月23日Nginx优化实战(进程管理、防盗链)
Nginx进程管理实例:
[root@nginx nginx-1.12.2]# cd /usr/local/nginx/[root@nginx nginx]# lsclient_body_temp fastcgi_temp logs sbin uwsgi_tempconf html proxy_temp scgi_temp[root@nginx nginx]# cd conf/[root@nginx conf]# vim nginx.conf//进行超时时间的设置keepalive_timeout 65 180;client_header_timeout 80;client_body_timeout 80;//修改完成后按Esc退出插入模式,输入:wq保存退出[root@nginx conf]# service nginx stop[root@nginx conf]# service nginx start[root@nginx conf]# ps aux | grep nginxroot 53792 0.0 0.0 20548 620 ? Ss 14:15 0:00 nginx: master process /usr/local/nginx/sbin/nginxnginx 53794 0.0 0.0 23076 1396 ? S 14:15 0:00 nginx: worker processroot 53818 0.0 0.0 112728 972 pts/0 R+ 14:15 0:00 grep --color=auto nginx//此时状态为一个master主进程,一个worker工作进程[root@nginx conf]#init 0
在虚拟机设置中扩展CUP,操作如下:
//查看cpu核心数:[root@nginx ~]# cd /proc/[root@nginx proc]# ls1 1607 1881 2016 247 33 499 587 992 kcore softirqs10 1613 1892 2074 2476 364 5 589 997 keys stat100 1620 19 21 248 381 500 599 acpi key-users swaps101 1621 1901 2119 25 391 501 6 buddyinfo kmsg sys1010 1679 1907 2168 256 394 502 601 bus kpagecount sysrq-trigger1011 1684 1914 22 257 396 503 604 cgroups kpageflags sysvipc1012 17 1920 2244 258 4 504 605 cmdline loadavg timer_list1044 1772 1934 2294 270 41 505 606 consoles locks timer_stats11 1787 1946 23 283 42 506 608 cpuinfo mdstat tty......此处省略多行,其中有我们需要查看的cpuinfo[root@nginx proc]# cat cpuinfo//第一核心:processor : 0vendor_id : GenuineIntelcpu family : 6model : 142model name : Intel(R) Core(TM) i5-8265U CPU @ 1.60GHzstepping : 11microcode : 0x9acpu MHz : 1799.452cache size : 6144 KBphysical id : 0siblings : 2core id : 0cpu cores : 2apicid : 0initial apicid : 0fpu : yesfpu_exception : yescpuid level : 22wp : yes//第二核心:processor : 1vendor_id : GenuineIntelcpu family : 6model : 142model name : Intel(R) Core(TM) i5-8265U CPU @ 1.60GHzstepping : 11microcode : 0x9acpu MHz : 1799.452cache size : 6144 KBphysical id : 0siblings : 2core id : 1cpu cores : 2apicid : 1initial apicid : 1fpu : yesfpu_exception : yescpuid level : 22wp : yes[root@nginx proc]# cd /usr/local/nginx/conf/[root@nginx conf]# vim nginx.confworker_processes 2; //把核心数1改成2//接下来进行平均分配worker_cpu_affinity 01 10; //插入此行//修改完成后按Esc退出插入模式,输入:wq保存退出[root@nginx conf]# service nginx start[root@nginx conf]# ps aux | grep nginxavahi 573 0.0 0.0 30248 1788 ? Ss 14:26 0:00 avahi-daemon: running [nginx.local]root 2759 0.0 0.0 20548 624 ? Ss 14:45 0:00 nginx: master process /usr/local/nginx/sbin/nginxnginx 2760 0.0 0.0 23076 1400 ? S 14:45 0:00 nginx: worker processnginx 2761 0.0 0.0 23076 1400 ? S 14:45 0:00 nginx: worker processroot 2782 0.0 0.0 112732 972 pts/0 S+ 14:45 0:00 grep --color=auto nginx//此时有两个worker工作进程
Nginx防盗链
win10中创建页面:
快乐每一天 this is happy web
在win10虚拟机中安装IIS服务:
将写好的网页放入以下路径:C:\inetpub\wwwroot
同时关闭防火墙功能
安装DNS服务:[root@nginx conf]# yum install bind -y
win10和win7的网络DNS地址改为192.168.18.136
[root@nginx conf]# vim /etc/named.confoptions { listen-on port 53 { any; }; //把括号中的127改为any listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; //把括号中的localhost改为any//修改完成后按Esc退出插入模式,输入:wq保存退出[root@nginx conf]# vim /etc/named.rfc1912.zoneszone "kgc.com" IN { type master; file "kgc.com.zone"; allow-update { none; };};//添加以上的内容,修改完成后按Esc退出插入模式,输入:wq保存退出[root@nginx conf]# cd /var/named/[root@nginx named]# cp -p named.localhost kgc.com.zone[root@nginx named]# vim kgc.com.zone$TTL 1D@ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1www IN A 192.168.18.136//修改完成后按Esc退出插入模式,输入:wq保存退出[root@nginx named]# systemctl start named[root@nginx named]# systemctl stop firewalld.service [root@nginx named]# setenforce 0
在win10和win7系统中使用cmd工具输入nslookup www.kgc.com进行域名解析,得到结果如下:
C:\Users\zhou>nslookup www.kgc.com服务器: UnKnownAddress: 192.168.18.136名称: www.kgc.comAddress: 192.168.18.136
我们使用win7访问win10的IP地址:192.168.18.139,得到盗链之后的页面:
我们使用win7访问:www.kgc.com,得到正常的Nginx的欢迎界面:
此时到盗链成功!接下来我们需要做的就是在Nginx中做防盗链!
[root@nginx named]# cd /usr/local/nginx/conf/[root@nginx conf]# vim nginx.conf root html; }//在以上内容下行插入以下内容location ~*\.(jpg|gif|swf)$ { valid_referers none blocked *.kgc.com kgc.com; if ( $invalid_referer ) { rewrite ^/ http://www.kgc.com/yy.png; }}//修改完成后按Esc退出插入模式,输入:wq保存退出[root@nginx conf]# cp /aaa/yy.png /usr/local/nginx/html/[root@nginx conf]# cd ../html/[root@nginx html]# ls50x.html index.html lf.jpg yy.png[root@nginx conf]# service nginx stop[root@nginx conf]# service nginx start
我们使用win7访问win10的IP地址:192.168.18.139,此时会跳出防盗链的图片:
此时防盗链大成功!
输入
模式
进程
防盗
核心
内容
地址
服务
成功
接下来
括号
页面
工作
管理
快乐
两个
功能
同时
名称
图片
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
长沙财务软件开发中心
电力网络安全怎么分区的
布比北京网络技术有限公司股票
电脑服务器多少钱
宝可梦无法连接到服务器
安装鸿蒙系统连接服务器失败
神武连接服务器超时c1003
江苏省网络安全宣传周在无锡
江苏服务器机柜报价
qq邮箱转发服务器
饥荒联机版需要多大的服务器
服务器运行硬盘灯会闪红色
计算机网络技术的人生目标
互联网科技怎么创业
wincc c 数据库
网络安全风险管理主要内容
metinfo数据库搬家
打一软件开发语言
图片如何删除数据库
网络安全基础设施名录
gta4联机服务器
测量数据库实习心得
软件开发济南
网络安全知识真文
重庆宣传网络安全
权限工作流数据库表
小白评测数据库打开应用速度
数据库处理是指对数据的什么总和
云南电信dns服务器云空间
软件开发部门年终项目总结