Implementation code of Nginx anti-hotlink and optimization in Linux

Implementation code of Nginx anti-hotlink and optimization in Linux

Hide version number

The version number is not hidden. To improve security, the version number needs to be hidden.

insert image description here

Hiding version number experiment

cd /usr/local/nginx/
### Edit the configuration file vim conf/nginx.conf 

insert image description here
insert image description here

Modify User Group

The main process uses root, and the subprocess uses the nginx user

insert image description here

vim conf/nginx.conf
### Specify user group user nginx nginx;

Set cache time

### Modified configuration file vim conf/nginx.conf 

insert image description here
insert image description here

Log cutting

Below is the log splitting script

#!/bin/bash
day=$(date -d "-1 day" "+%Y%m%d")
logs_path="/var/log/nginx"
pid_path="/usr/local/nginx/logs/nginx.pid"
[ -d $logs_path ] || mkdir -p $logs_path
mv /usr/local/nginx/logs/access.log ${logs_path}/access.log-$day
kill -USR1 $(cat $pid_path)
find $logs_path -mtime +30 -exec rm -rf {} \;

#### Use the log segmentation script to automatically segment the log every day chmod +x /opt/jiaoben.sh
crontab -e
0 1 * * * /opt/jiaoben.sh 

insert image description here

Achieving high concurrency by changing the number of CPU cores

### Check the number of CPUs cat /proc/cpuinfo | grep -c "physical id"
### Change the configuration file. The number of cores needs to correspond to your computer. vim conf/nginx.conf
### After setting, you need to restart the service. 

insert image description here

Configure web page compression

insert image description here

Configuring hotlink protection

~* \.(jpg|gif|swf)$ : This regular expression matches case-insensitive image formats.
walid_referers: specifies the trusted domain name. 

insert image description here

optimization

This can be optimized by the following code

vim /usr/local/php/etc/php-fpm.d/www.conf
--96 lines--
pm = dynamic #fpm process startup mode, dynamic --107 lines--
pm.max_children=20 #The maximum number of processes started by the fpm process--112 lines--
pm.start_servers = 5 #The default number of processes started when starting in dynamic mode is between the minimum and maximum --117 lines--
pm.min_spare_servers = 2 #Minimum number of idle processes in dynamic mode --122 lines--
pm.max_spare_servers = 8 #Maximum number of idle processes in dynamic mode kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` #Restart php-fpm
netstat -anpt | grep 9000

The above is the details of Nginx anti-hotlink and optimization in Linux. For more information about Nginx anti-hotlink and optimization, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • 3 ways to prevent hotlinks in Nginx
  • Nginx Anti-Hotlink Configuration Method
  • Introduction to the method of anti-hotlinking under Nginx server
  • Nginx image hotlink protection configuration example
  • How to configure Nginx's anti-hotlinking
  • Complete steps for Nginx to configure anti-hotlinking
  • The whole process of Nginx anti-hotlink and service optimization configuration

<<:  When MySQL is upgraded to 5.7, WordPress reports error 1067 when importing data

>>:  Essential tools for web design: Firefox Web Developer plugin CSS tool set tutorial

Recommend

The normal method of MySQL deadlock check processing

Normally, when a deadlock occurs, the connection ...

Deep understanding of the use of ::before/:before and ::after/:after

Part 1: Basics 1. Unlike pseudo-classes such as :...

MySQL slow query pt-query-digest analysis of slow query log

1. Introduction pt-query-digest is a tool for ana...

8 examples of using killall command to terminate processes in Linux

The Linux command line provides many commands to ...

Summary of Seven Basic XHTML Coding Rules

1. All tags must have a corresponding end tag Prev...

Install zip and unzip command functions under Linux and CentOS (server)

Install zip decompression function under Linux Th...

Summarize how to optimize Nginx performance under high concurrency

Table of contents Features Advantages Installatio...

Method example of safely getting deep objects of Object in Js

Table of contents Preface text parameter example ...

Analysis of the process of building a cluster environment with Apache and Tomcat

In fact, it is not difficult to build an Apache c...

HTML Tutorial: Ordered Lists

<br />Original text: http://andymao.com/andy...

CSS3 to achieve simple white cloud floating background effect

This is a very simple pure CSS3 white cloud float...

Detailed steps for installing and configuring MySQL 8.0 on CentOS

Preface Here are the steps to install and configu...

Summary of examples of common methods of JavaScript arrays

Table of contents Common array methods concat() M...

HTML iframe usage summary collection

Detailed Analysis of Iframe Usage <iframe frame...