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
Then restart the service and check whether the version number has been hidden
Counterfeit version 1.2
Went to the file before, turn it on, do not hide
Then we can step by step into the modified version of the document
In this position you can modify the version number, complete change save and exit
Save and exit, have to recompile
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
Optimize cache one day
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
After installation, the following load these services (if error, you can try the next reboot the firewall)
At this time we can open the apache service
Do step by step test, let's see if you can access
Access, Mo was a problem
Next was to install these mariadb
Then start mariadb
3306 filter port
Then we have to file under this set
Next, set a password, including several decisions have selected no, yes the last election on the line
Then install php
php and mysql connection packets have to install
The next step is to install a lot of php plugin, be careful not to leak
After get to the following positions, modifying the file
Finally, do not forget to restart the service
Then we go to page test
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
Still the same archive can go to the official website to download, and then mount copied. I used rz
Decompression
Creating a user program
Installation environment package
Enter the following configuration after installation these
Then make the compiler
Let command allows the system to identify, to build a directory
Write a startup script
Save and exit
Give execute permissions and add services
Then is a series of open service, 80-port and turn off the firewall
Successful visit to page
Next apache nginx before the dynamic request to that machine, we can go to the following modify this file
Locate the following three lines, three lines is used for static and dynamic separation, we need to turn to him and change it
Restart Service
Access php dynamic pages can be found again visited
4.Log division
Let's move to the following directory
First, we look at the date of this order
If we enter the date correctly following the specific time will appear
We can change the next display format allowed
-1 for the digital change means that yesterday
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
Save and exit to give execute permissions
carried out
Next, we we went to the log file should be able to find nginx, and found that there are log
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
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
Once saved, restart the service
6.nginx compression
Enter the main configuration file
Follows
But such a mess, we put these elements break down
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.