The web container should be more accurately called a web server (Python's web container includes web.py, etc.), which is used to manage and deploy web applications.
So, Nginx is a web container. The official introduction is that Nginx is a lightweight web server/reverse proxy server and electronic server. Mail (IMAP/POP3) proxy server, released under the BSD-like license.
Its characteristics are that it occupies less memory and has strong concurrency capabilities. In fact, nginx’s concurrency capabilities do perform better among web servers of the same type.
Users of nginx websites in mainland China include: Baidu, JD.com, Sina, NetEase, Tencent, Taobao, etc.
The following is an example of Nginx serving as a web container to process static pages.
I have read a lot of other people’s tuning experiences, including setting Linux kernel parameters, setting nginx parameters, setting php-fpm, and modifying nginx source code and recompiling.
First, nginx parameter setting
user www www; #worker进程的用户 worker_processes 8; #一般和CPU核数一致 worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000; #error_log /www/log/nginx_error.log crit; #为了得到更好的IO我是关闭日志的 pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 204800; events { use epoll; worker_connections 204800; } http { include mime.types; default_type application/octet-stream; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 2k; large_client_header_buffers 4 4k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; fastcgi_cache_path /usr/local/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 4k; fastcgi_buffers 8 4k; fastcgi_busy_buffers_size 8k; fastcgi_temp_file_write_size 8k; fastcgi_cache TEST; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1; fastcgi_cache_use_stale error timeout invalid_header http_500; open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 8080; server_name localhost; index index.php index.htm; root /www/html/; location /status { stub_status on; } location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } log_format access '$remote_addr -- $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; #access_log /www/log/access.log access; } }
When accessing static resources, under the premise that worker_proccess and worker_connections are set correctly, the biggest performance improvement is
open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s;
This Several items, cache file resources. I used ab to test the explosive growth of performance. It originally took 10 seconds to send 1,000 requests and 1,000 concurrent requests. After adding it, it immediately became 0.4. The throughput rate has changed from dozens of K to 1M. I have a single-core 1G virtual machine configuration. . .
So what about accessing PHP files?
fastcgi_cache_path /usr/local/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 4k; fastcgi_buffers 8 4k; fastcgi_busy_buffers_size 8k; fastcgi_temp_file_write_size 8k; fastcgi_cache TEST; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1; fastcgi_cache_use_stale error timeout invalid_header http_500;
Can significantly improve efficiency
The most effective way to improve nginx efficiency is to enable various caches!
For more Nginx related technical articles, please visit the Nginx usage tutorial column to learn!
The above is the detailed content of Is nginx a web container?. For more information, please follow other related articles on the PHP Chinese website!