Nginx server sets static page compression cache and expiration time

Set static page compression cache and expiration time settings in nginx: Friends who use the nginx server may know that it is necessary to set the html static page cache, page compression and expiration time settings. Let me introduce the configuration method to you, including ico, gif, bmp, jpg, jpeg, swf, js , css, mp3 files are cached locally. You can use nginx to set the expiration time of the static resources on the server and compress and transmit the resources to reduce the bandwidth overhead of the server. The following is how nginx sets the expiration time of static resources: location ~* .(ico|gif|bmp|jpg|jpeg|png|swf|js|css|mp3) { root /var/www/opkeep; expires 30d; } The above configuration can cache ico, gif, bmp, jpg, jpeg, swf, js, css, mp3 files locally, without re-acquiring them from the server every time they are accessed. The compressed configuration is as follows: gzip on; gzip_min_length 1000; gzip_buffers 4 8k; gzip_types text/plain application/x-Javascript text/css; Compress text, js and css files. Generally, the compressed size is 25% of the original size, or even smaller. Cache dynamic pages, cache expiration time Here is the configuration of the virtual machine: nginx configuration file content: Mainly this sentence: proxy_cache_path /www/ levels=1:2 keys_zOne=Z:10m inactive=1m max_size=30g;…

Use Nginx to deploy a high-performance web server

Use Nginx to deploy a high-performance web server

What are we going to learn this time? It is to use Nginx to build the simplest web server displaying “Hello World” on a machine. then we will Step by step let’s try~ 1. Nginx package The latest development version is 1.1.12: We can download the stable version to try: 2. Download, decompress, and install Nginx Here we take Linux/Unix: nginx-1.0.11.tar.gz as an example. Download and unzip: wget http://nginx.org/download/nginx-1.0.11.tar.gz tar -zxvf nginx-1.0.11.tar.gz But do not rush to install after downloading and decompressing, because Nginx depends on a lot of software, we assume that your Linux environment is “clean”, so the following is mentioned All packages that Nginx depends on. Please follow the steps below to install: sudo apt-get install gcc sudo apt-get install g++ sudo apt-get install make sudo apt-get install libz-dev sudo apt-get install libbz2-dev sudo apt-get install libreadline-dev This is some basic software, plus PCRE to install. PCRE stands for “Perl Compatible Regular Short for “Expressions”, is a regular expression library. Download, extract and install PCRE: wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz tar -zxvf pcre-8.13.tar.gz cd pcre-8.13.tar.gz ./configure sudo make sudo make install At this time, install the nginx-1.0.11.tar.gz we just downloaded tar -zxvf nginx-1.0.11.tar.gz cd nginx-1.0.11 ./configure sudo make sudo make…

Start and stop of PHP-fpm service

Versions above php 5.3.3 will integrate php-fpm into the kernel, and there is no need to apply patches after installing fast-cgi in the future. Have fun. Using php-fpm in future versions will require some related operations on php-fpm through signal control. details as follows: SIGINT, SIGTERM terminate immediately SIGQUIT graceful termination SIGUSR1 reopen log file SIGUSR2 gracefully reloads all worker processes and reloads configuration and binary modules Example: INT, TERM terminate immediately QUIT Smooth termination USR1 reopen log file USR2 Smoothly reload all worker processes and reload configuration and binary modules notice: The above signal instructions are full spelling, and the examples are abbreviated. Among them, “/usr/local/php/var/run/php-fpm.pid” is the running process of the php-fpm you installed. If you don’t know what process file is running on your machine, you can check it with the following command. Reposted from: http://hi.baidu.com/xc_hai/blog/item/ac1e3dfa3cef57344e4aea93.html Starting from php5.3.3, the source code begins to include php-fpm, no need to patch it, just unpack the source code and configure directly, The compilation parameters for php-fpm are ?enable-fpm ?with-fpm-user=www ?with-fpm-group=www ?with-libevent-dir=libevent location. This php-fpm no longer supports /usr/local/php/sbin/php-fpm which the php-fpm patch has (start|stop|reload) and other commands need to use signal control: The master process can understand the following…

Performance testing and use of nginx_lua

Performance testing and use of nginx_lua

For the choice of high-performance web servers, this is a headache for many people. In fact, Apache, lighttpd, and Nginx all use their advantages. Under what circumstances, how do we choose a high-performance Web server that suits us, and how to build a framework environment that suits us? This is a very troublesome thing. Next, in the ADC 2012 (Alibaba Developer Conference 2012) conference, 51CTO reporter had the honor to interview Yitao Data Platform and Product Department technical expert – Qingwu (nickname), to explain some advantages and disadvantages of Nginx_lua for us, as well as the choice of high-performance servers. First, let us understand the design guiding ideology of Nginx_lua: 1. Rapidly develop high-performance, high-concurrency network services based on Nginx. 2. Provide a “synchronous non-blocking” I/O access interface to simplify business logic development in the I/O multiplexing system: ■ The subject of “synchronization” is the timing relationship between the user code and the I/O request processing flow initiated by it, which means that the user code will be suspended until the I/O request processing is completed. ■ The main body of “non-blocking” is the service process, which means that the processing of I/O requests will not cause the service process…

CentOS6.5 system installation and configuration Nginx-1.2.7+PHP-5.3.22 environment

One, operating system Install the system in the form of a minimal server, and add a development tool library for later compilation and use. Here is basically the next step, the next step, no more nonsense. After the installation is complete, enter the system, adjust the network, close the firewall or open the corresponding WEB port. The following installation operations are performed in the /root directory by default. Second, nginx installation Download pcre and zlib, everyone on earth knows… wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz tar -zxvf pcre-8.32.tar.gz cd pcre-8.32 ./configure make && make install wget http://zlib.net/zlib-1.2.7.tar.gz tar -zxvf zlib-1.2.7.tar.gz cd zlib-1.2.7 ./configure make && make install Download the current latest stable version nginx-1.2.7 cd wget http://nginx.org/download/nginx-1.2.7.tar.gz tar -zxvf nginx-1.2.7.tar.gz cd nginx-1.2.7 ./configure –prefix=/usr/local/nginx/ –with-pcre=/root/pcre-8.32 –with-zlib=/root/zlib-1.2.7 make && make install /usr/local/nginx/sbin/nginx Started, open the browser to test nginx. Three, install the PHP environment Download the current stable version php-5.3.22 wget http://www.php.net/get/php-5.3.22.tar.gz/from/cn1.php.net/mirror tar -zxvf php-5.3.22.tar.gz Before starting to compile, install some basic php packages and install them directly with yum. yum -y install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql mysql-devel When ready, go to the php directory to compile cd php-5.3.22 ./configure –prefix=/usr/local/php –enable-fastcgi –enable-fpm –enable-debug –with-gd –with-jpeg-dir –with-png-dir…

Nginx multi-process model implementation details analysis

Foreword: “ Server programs usually control the work of the server through corresponding configuration files. In many cases, the configuration file will be modified frequently. When making it take effect, we hope that the program will not be restarted and the normal service of the server will not be affected. So the so-called “hot loading” of configuration files has become a very important function, and in this regard, nginx has set a very good example for us, which is worth learning and learning from. analyze: “ When nginx is in normal service, we execute ./nginx in the program directory of nginx ?sreload, to reload the configuration file. The function of -s is to send a signal to the master process. In addition to the reload function, stop, reopen, etc. can also be used. Specifically, you can view it through -h. When executing ./nginx ?s After reload, save the “reload” string through ngxs_signal, and then pass it through ngx_signal_process To send a signal to the currently running nginxmaster process. if (ngx_signal) { “ return ngx_signal_process(cycle, ngx_signal); } By reading the code, we can see that sending a signal to the currently running nginx process is actually restarting a copy of nginx,…

Use Nginx+Mono+Fastcgi to configure ASP.NET operating environment

Use Nginx+Mono+Fastcgi to configure ASP.NET operating environment

The benefits of Nginx believe that I don’t need to say more, as a fairly lightweight open source Web server and reverse proxy server are very popular. More and more companies have become interested in it, including many departments of our company, using it for load balancing and resource management. I wrote an article about using Nginx for load balancing article (http://www.cnblogs.com/liping13599168/archive/2011/04/15/2017369.html). “ This article introduces how to reverse proxy through Nginx and run the asp.net website. I use the Win7 system for the test environment. First, you need to download the Nginx installation package: http://nginx.org/en/download.html, here I download the latest version: nginx/Windows-1.1.16 Unzip the package to see the directory: Nginx is the entry of the execution file, open the conf directory, you can see the nginx.conf file, this is the main configuration entry of Nginx: server { listen 8000; “ server_name` 127.0.0.1; #charset koi8-r; … } Here I change the default 80 to 8000 as the default port of the nginx web server. From here we can understand that 8000 is the web port announced by the website, that is, the port of the proxy service. Now, I can let it host the internal Related Web sites on the…

Nginx server restart script

nginx is a super stable server. Generally, it will not need to be restarted due to overload problems. The purpose of restarting is generally to load after modifying the configuration file. At the beginning, I used the most direct way to restart killall -9 nginx;/data/nginx/sbin/nginx If the machine is relatively slow, the kill process cannot be killed in an instant, just execute it again. This restart method is not particularly safe. If the configuration is wrong, the restart will fail, and the configuration file needs to be modified before restarting, which will take a little time. However, for the currently generally not very strict http industry, this time will not cause too much loss, as long as it is not done at a critical moment. If you want to continue to use this restart method, I suggest that you should test it first. Later I saw a more fantastic restart on nginx.net kill -HUP $pid ($pid is the process number of the nginx master process) I usually use it like this kill -HUP `cat /data/nginx/logs/nginx.pid` The advantage of this method is to achieve “smooth restart”, in ps In -aux, it can be seen that nginx starts a new process first,…

Use Lua scripting language to operate Redis in Nginx server

Use the Lua scripting language to operate Redis. Since a lot of Lua code is written in Nginx , it will make the configuration file very cumbersome, so here use content_by_lua_file to introduce Lua script file. To use content_by_lua_file, the nginx_lua_module module needs to be installed. Installation introduction, click here: nginx_lua_module The great god Zhang Yichun provides a very convenient development kit, as follows: git clone https://github.com/agentzh/lua-resty-redis.git In this package, there is a Lib directory, copy the files and subdirectories under the Lib directory to the directory /data/www/lua In the Nginx configuration file, you need to add a line of code to import redis.lua. Note: Add in the http segment. lua_package_path “/data/www/lua/?.lua;;”; In order to make the modification of the lua script take effect in time, a line of code needs to be added, as follows: Note: In the server section, add code. If you do not add this code or set it to on, you need to restart Nginx. lua_code_cache off; In the Nginx configuration file, add a Location: location /lua { content_by_lua_file /data/www/lua/test.lua; } Note: import test.lua script file Lua script file: test.lua. local redis = require “resty.redis” local cache = redis.new() local ok, err = cache.connect(cache, ‘127.0.0.1’,…

Varnish, squid, Apache, Nginx performance efficiency test comparison

Varnish, squid, Apache, Nginx performance efficiency test comparison

One, test environment 1. The hardware is Pentium dual-core, which was purchased three years ago. The system is archlinux 2. When testing varnish and squid, the apache used for web services 3. When testing apache, five processes are started, but as the pressure increases, the process will increase. 4. When testing nginx, ten nginx processes and 20 php-cgi processes were started 5. Varnish, squid, and nginx use the form of reverse proxy, that is to say, when accessing pictures, you must first use the cache tool Second, test 1, varnish [root@BlackGhost bin]# /usr/local/bin/webbench -c 100 -t 20 http://127.0.0.1:8080/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif Webbench – Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://127.0.0.1:8080/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif 100 clients, running 20 sec. Speed=476508 pages/min, 47258114 bytes/sec. Requests: 158836 succeeded, 0 failed. Varnish’s cache efficiency hit rate is really high, see the picture below: varnish After visiting so many times, there is only one time without caching, and the efficiency is really high. 2, squid [root@BlackGhost bin]# /usr/local/bin/webbench -c 100 -t 20 http://localhost:9000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif Webbench – Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://localhost:9000/00/01/RwGowEtWvcQAAAAAAAAWHH0Rklg81.gif 100 clients, running 20 sec. Speed=133794 pages/min, 7475018 bytes/sec. Requests: 44598…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索