In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to optimize the configuration of Nginx". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to optimize the configuration of Nginx.
What is Nginx?
Before this, I have also introduced the relevant content and installation process, which is widely used in the actual production operation and maintenance environment, but it is still necessary to understand and understand some of its powerful functions and features in detail.
As a lightweight HTTP server, Nginx has obvious advantages over Apache. In performance, it takes up less resources and can support higher and more concurrent connections, thus improving access efficiency; functionally, it is a very excellent proxy server and load balancing server; in installation and configuration, it is relatively simple to install and configure.
Introduction to the benefits of Nginx:
Often in the operation and maintenance interview, the interviewer will ask, what HTTP server do you use? Why use it?
1. As a WEB server, Nginx is more efficient in dealing with static files.
2. As a proxy server, Nginx can achieve cacheless reverse proxy acceleration to improve the running speed of WEB sites and improve the experience of users' access.
3. As a load balancing server, it not only supports many applications, but also supports fault tolerance, and has its own algorithm for load balancing scheduling.
4. In terms of performance, the kernel poll model is adopted to support more concurrent connections. Officially, it can support a request response of up to 50000 concurrent connections, but it takes up little resources and is very stable.
Daily configuration optimization of Nginx
1. Log cutting
Since Nginx does not have the cronolog log cutting function of Apache service, it needs to be optimized, and scripts can be written to automatically cut log files.
#! / bin/sh
Logpath= "/ nginx/logpath"
Nginxlogs= "/ var/log/nginx/"
Mkdir-p $logpath/$ (date +% Y)
Mv $nginxlogs/access.log $logpath/$ (date +% Y) / access_$ (date + F) .log
Mv $nginxlogs/error.log $logpath/$ (date +% Y) / access_$ (date + F) .log
Kill-USR1 `cat / var/log/nginx/ nginx.pid`
# # Control the process through USR1 signals to regenerate a new log file
Nginx has a very strong function to control the process, and can control the process through signal instructions. The common signals are as follows.
QUIT shuts down the process after processing the current request
HUP reloads the configuration without interrupting users' access requests
USR1 is used to cut logs
USR2 is used to smoothly upgrade executables
Finally, the script execution command is added to the scheduled task to automatically cut the log.
2. Optimization of FastCGI parameters in nginx.
To improve the running efficiency of PHP in nginx environment, you can add the following configuration to the main configuration file
Fastcgi_cache_path / application/nginx/fastcgi_cache_levels=1:2 keys_zone=TEST:10m inactive=5m
Fastcgi_connect_timeout 300
Fastcgi_send_timeout 300
Fastcgi_read_timeout 300
Fastcgi_buffer_size 64k
Fastcgi_buffers 4 64k
Fastcgi_busy_buffers_size 128k
Fastcgi_cache TEST
Fastcgi_cache_valid 200 302 1h
Fastcgi_cache_valid 3011d
Fastcgi_cache_valid any 1m
# # response caching time
3. HTTPgzip module configuration of nginx
[root@centos7] # / usr/local/nginx/sbin/nginx-V
Nginx version: nginx/1.12.0
Built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
Built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
Configure arguments:-with-http_stub_status_module-- with-http_gzip_static_module-- with-http_ssl_module-- prefix=/usr/local/nginx
You can see that this module has been added at compile time, so you only need to configure it in the configuration file
Gzip on
Gzip_min_length 1k
Gzip_buffers 4 16k
Gzip_http_version 1.1
Gzip_comp_level 2
Gzip_types text/plain application/x-javascript text/css application/xml
Gzip_vary on
At this point, I believe you have a deeper understanding of "how to optimize the configuration of Nginx". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.