Nginx optimization (version hidden cache optimization, static and dynamic separation, splitting logs, process management, compression)

Nginx optimization

Preface: Before you have seen the installation of nginx, nginx optimization under the terms of a matter of course. Usually we use a computer just like using a mobile phone had to optimize the next. Nginx is a high-performance HTTP server and reverse proxy, lightweight, highly concurrent web server.

In the actual production environment, we still can not directly use the default configuration of Nginx to act as a server. After all, in order to more fully rational use Nginx server, we should make some necessary adjustments to the default configuration nginx according to their actual needs. Optimization as follows.

1. Hide the version number

Hidden version 1.1

This configuration file into the modification

mark mark

Then restart the service and check whether the version number has been hidden

mark

Counterfeit version 1.2

Went to the file before, turn it on, do not hide

mark mark

Then we can step by step into the modified version of the document

mark mark

In this position you can modify the version number, complete change save and exit

Save and exit, have to recompile

mark mark mark

Then restart the service to view the version number on the list. However, this method only on changing for the better version before installing nginx. If you have already installed the nginx, and then forged version number, have to be recompiled, it would be too much trouble. So this method is not particularly recommended.

2. Cache optimization

Enter profile

mark

Optimize cache one day

mark

After the restart the service, you can use the packet capture tool verification. Because it is optimized cache image format, and I did not add pictures here, and there is no obvious effect. Interested can go to get some pictures and more try to see the effect after optimization.

3. static and dynamic separation

3.1 must first install apache

mark

After installation, the following load these services (if error, you can try the next reboot the firewall)

mark mark mark

At this time we can open the apache service

mark

Do step by step test, let's see if you can access

mark

Access, Mo was a problem

Next was to install these mariadb

mark

Then start mariadb

mark

3306 filter port

mark

Then we have to file under this set

mark

Next, set a password, including several decisions have selected no, yes the last election on the line

mark mark

Then install php

mark

php and mysql connection packets have to install

mark

The next step is to install a lot of php plugin, be careful not to leak

mark

After get to the following positions, modifying the file

mark mark mark

Finally, do not forget to restart the service

mark

Then we go to page test

mark

Currently we built a good part of this dynamic, the next part is static nginx

3.2nginx and we usually set up is the same, but we have to build the replacement host for operation

To prevent misunderstanding under the same name, where the name of the user to change the root, facilitate the distinction

mark

Still the same archive can go to the official website to download, and then mount copied. I used rz

mark

Decompression

mark

Creating a user program

mark

Installation environment package

mark

Enter the following configuration after installation these

mark

Then make the compiler

mark

Let command allows the system to identify, to build a directory

mark

Write a startup script

mark mark mark

Save and exit

Give execute permissions and add services

mark

Then is a series of open service, 80-port and turn off the firewall

mark

Successful visit to page

mark

Next apache nginx before the dynamic request to that machine, we can go to the following modify this file

mark

Locate the following three lines, three lines is used for static and dynamic separation, we need to turn to him and change it

mark mark

Restart Service

mark

Access php dynamic pages can be found again visited

mark

4.Log division

Let's move to the following directory

mark

First, we look at the date of this order

If we enter the date correctly following the specific time will appear

mark

We can change the next display format allowed

mark

-1 for the digital change means that yesterday

mark

xargs meaning: a command execution result of the preceding execution of the command as a parameter back

Know there is probably some of the parameters of meaning, we can write the following script

mark mark

Save and exit to give execute permissions

mark

carried out

mark

Next, we we went to the log file should be able to find nginx, and found that there are log

mark

5.nginx process management

We set the timeout to nginx access time, prevent long-term occupation of resources

Let's switch to the position under the nginx conf file

mark

Then set timeout themselves how much time to control the line, in front of keepalive 65 is the server time-out, followed by 180 client timeout

mark

Once saved, restart the service

mark

6.nginx compression

Enter the main configuration file

mark

Follows

mark

But such a mess, we put these elements break down

mark

Something like this you can save and exit, and mark where the red box is supported compression features, such as jpg, when nginx among them pictures jpg format, it will be compressed to achieve the purpose of optimization.

Summary: The experimental system is optimized to do a nginx, of which there are a lot of scripts and configuration parameters, it is difficult to remember, but we have to understand which probably meant. Their own and then follow the script written test, so that later do a similar experiment, even if not, at least at his pair of scripts I know how to engage. If you can not read other people write, you see your own scripts understand, and that is the Wizards, exclusive of the original.
Published 43 original articles · won praise 7 · views 1014

Guess you like

Origin blog.csdn.net/qq_45682385/article/details/104078666