Nginx optimization practice (process management, hotlink protection)
Nginx process management example: [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// to set the timeout for timeout 65 180 / / Press Esc to exit the insertion mode after modification, and enter: wq save exit [root@nginx conf] # service nginx stop [root@nginx conf] # service nginx start [root@nginx conf] # ps aux | grep nginxroot 53792 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 112728 972 pts/0 R + 14:15 0:00 grep-- color=auto nginx// is a master main process at this time, and a worker worker process [root@nginx conf] # init 0 extends CUP in the virtual machine settings as follows:
/ check the number of cpu cores: [root@nginx ~] # cd / proc/ [root@nginx proc] # ls1 1607 1881 2016 247 33 499 587,992 kcore softirqs10 1613 1892 2074 2476 364 5589,997 keys stat100 1620 19 21 248 381 500599 acpi key-users swaps101 1621 1901 2125 391 501 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. Multiple lines are omitted here There are cpuinfo [root@nginx proc] # cat cpuinfo// first core: 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// second core: 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 / / change the number of cores from 1 to 2; then evenly distribute worker_cpu_affinity 01 10; / / insert this row / / press Esc to exit insert mode after modification, and enter: wq save exit [root@nginx conf] # service nginx start [root@nginx conf] # ps aux | grep nginxavahi 573 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 112732 972 pts/0 S+ 14:45 0:00 grep-- color=auto nginx// has two worker worker processes at this time Nginx hotlink protection win10 created page: happy every day this is happy web
Install the IIS service in the win10 virtual machine:
Put the written web page in the following path: C:\ inetpub\ wwwroot also turn off the firewall function to install the DNS service: [root@nginx conf] # yum install bind-ywin10 and win7 change the network DNS address to 192.168.18.136 [root@nginx conf] # vim / etc/named.confoptions {listen-on port 53 {any;}; / / change the parentheses to 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;}; / / change the localhost in parentheses to any//, press Esc to exit the insertion mode after modification, and enter: wq save exit [root@nginx conf] # vim / etc/named.rfc1912.zoneszone "kgc.com" IN {type master; file "kgc.com.zone"; allow-update {none;};} / / add the above, press Esc to exit the insertion mode after modification, and enter: wq save exit [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 setenforce / after modification, press Esc to exit insert mode, enter: wq save exit [root@nginx named] # systemctl start named [root@nginx named] # systemctl stop firewalld.service [root@nginx named] # setenforce 0 use the cmd tool to enter nslookup www.kgc.com for domain name resolution in win10 and win7 systems The results are as follows: C:\ Users\ zhou > nslookup www.kgc.com server: UnKnownAddress: 192.168.18.136 name: www.kgc.comAddress: 192.168.18.136 We use win7 to access the IP address of win10: 192.168.18.139 to get the page after the hotlink:
We use win7 to visit: www.kgc.com to get a normal Nginx welcome interface:
At this point to the success of the hotlink! The next thing we need to do is do hotlink protection in Nginx! [root@nginx named] # cd / usr/local/nginx/conf/ [root@nginx conf] # vim nginx.conf root html;} / / insert the following in the lower line of the above content location ~ *\. (jpg | gif | swf) ${valid_referers none blocked *. Kgc.com kgc.com; if ($invalid_referer) {rewrite ^ / http://www.kgc.com/yy.png; }} / / Press Esc to exit insert mode after modification, enter: wq save exit [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 We use win7 to access win10's IP address: 192.168.18.139 The image of hotlink protection will pop up at this time:
At this time, the anti-theft chain is a great success!