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

Detailed explanation of Vuex overall case

Table of contents 1. Introduction 2. Advantages 3...

Detailed explanation of the wonderful CSS attribute MASK

This article will introduce a very interesting at...

Writing a shell script in Ubuntu to start automatically at boot (recommended)

The purpose of writing scripts is to avoid having...

How to install Chrome browser on CentOS 7

This article introduces how to install Chrome bro...

Javascript destructuring assignment details

Table of contents 1. Array deconstruction 2. Obje...

Discussion on the Issues of Image Button Submission and Form Repeated Submission

In many cases, in order to beautify the form, the ...

Five guidelines to help you write maintainable CSS code

1. Add a comment block at the beginning of the sty...

AsyncHooks asynchronous life cycle in Node8

Async Hooks is a new feature of Node8. It provide...

Quickly learn MySQL basics

Table of contents Understanding SQL Understanding...

express project file directory description and detailed function description

app.js: startup file, or entry file package.json:...

Detailed explanation of Linux command unzip

Table of contents 1. unzip command 1.1 Syntax 1.2...

Swiper.js plugin makes it super easy to implement carousel images

Swiper is a sliding special effects plug-in built...

How to completely delete and uninstall MySQL in Windows 10

Preface This article introduces a tutorial on how...

CSS to achieve the effect of rotating flip card animation

The css animation of the rotating flip effect, th...