In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
How do I use Nginx caching to speed up WordPress sites? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Since the launch of the blog, it has mainly recorded the problems and solutions encountered in the process of learning and using. The style of the article tends to entertain itself, so the number of visits is less, and a 1-core 1G vps is enough to support the normal operation of the website.
Later, this site introduced three pages, these three pages should be very helpful to the netizens who need to go to the foreign network, but also brought a lot of traffic to this site. The WordPress program used by this site has tried to install various cache plug-ins (super cache, w3 total cache, etc.) to speed up the operation, but the low-configuration vps is still difficult to support such a large number of visitors. Through the log, we can see that as the number of visits increases, the number of php-fpm processes increases, the connections and threads of Mysql increase, then OOM appears, and then the system kill drops the Mysql process that takes up the most memory, so the website enters 503downtime mode.
Buying a better vps can solve the problem of high traffic, but it costs more money. As a technologist, the first thing that comes to mind is, of course, how to drain existing machines to support heavy traffic. Attempts have been made to switch to Ghost with better performance than WordPress. See: try Ghost. But compared with the ecology of WordPress,Ghost, it is far from mature and finally gives up.
On second thought, the ultimate solution is to use Nginx caching, which can be found in the original article: Nginx configuring fastcgi cache. The advantage of fastcgi_cache is that most users' requests do not have to deal with back-end php-fpm, send cached static pages directly, and dump various WordPress plug-ins for several blocks in speed! In contrast, the various plug-ins of wordpress also have to implement php, which can not avoid accessing the database, which is very weak.
Since the use of nginx cache, the website runs smoothly, and there is no downtime. At the same time, the cpu and memory occupancy of vps have plummeted, so there is no need to worry about the configuration of vps. It feels like a blog with 10 times traffic can hold up.
Because nginx is as stable as a dog's experience, products that read more and write less on blogs now push nginx caching (fastcgi caching or proxy caching). In view of the possibility of helping some netizens, the / etc/nginx/nginx.conf configuration file is posted for netizens' reference (including ssl settings and gzip section):
# File: / etc/nginx/nginx.conf# For more information on configuration, see:# * Official English Documentation: http://nginx.org/en/docs/# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes auto;error_log / var/log/nginx/error.log;pid / run/nginx.pid;# Load dynamic modules. See / usr/share/nginx/README.dynamic.include / usr/share/nginx/modules/*.conf;events {worker_connections 1024;} http {log_format main'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"$request_time"' Access_log / var/log/nginx/access.log main buffer=32k flush=30s; server_tokens off; client_max_body_size 100m; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include / etc/nginx/mime.types; default_type application/octet-stream # ssl configuration ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384; ssl_ecdh_curve secp384r1; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_session_tickets off; ssl_stapling on # Requires nginx > = 1.3.7 ssl_stapling_verify on; # Requires nginx = > 1.3.7 add_header Strict-Transport-Security "max-age=63072000; preload"; # add_header X-Frame-Options DENY; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block" # Please change fastcgi_cache_path / var/cache/nginx/tlanyan levels=1:2 keys_zone=tlanyan:10m inactive=30m use_temp_path=off; fastcgi_cache_key $request_method$scheme$host$request_uri; # note: can also use HTTP headers to form the cache key, e.g. # fastcgi_cache_key $scheme$request_method$host$request_uri$http_x_custom_header; # fastcgi_cache_lock on; fastcgi_cache_use_stale error timeout invalid_header updating http_500 according to your needs Fastcgi_cache_valid 200301 302 10h; fastcgi_cache_valid 404 10m; fastcgi_ignore_headers Expires Set-Cookie Vary; # gzip configuration gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_comp_level 7 Gzip_types text/css text/plain text/javascript application/javascript application/json application/x-javascript application/xml application/xml+rss application/xhtml+xml application/x-font-ttf application/x-font-opentype application/vnd.ms-fontobject image/svg+xml image/x-icon application/rss+xml application/atom_xml Image/jpeg image/gif image/png image/icon image/bmp image/jpg Gzip_vary on; # Load modular configuration files from the / etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. Include / etc/nginx/conf.d/*.conf;}
And the site profile (/ etc/nginx/conf.d/tlanyan.conf) for the WordPress site:
Server {listen 80; listen [:]: 80; server_name www.tlanyan.me tlanyan.me; # Please change it to your own domain name rewrite ^ (. *) https://$server_name$1 permanent;} server {listen 443 ssl http2; listen [::]: 443 ssl http2; server_name www.tlanyan.me tlanyan.me; # Please change it to your own domain name charset utf-8 Ssl_certificate / etc/nginx/conf.d/tlanyan.pem; # Please change your certificate and key ssl_certificate_key / etc/nginx/conf.d/tlanyan.key; set $host_path "/ var/www/tlanyan"; # change to your own path access_log / var/log/nginx/tlanyan.access.log main buffer=32k flush=30s; error_log / var/log/nginx/tlanyan.error.log; root $host_path # cache tag set $skip_cache 0; if ($query_string! = ") {set $skip_cache 1;} if ($request_uri ~ *" / wp-admin/ | / xmlrpc.php | wp-.*.php | / feed/ | sitemap (_ index)? .xml ") {set $skip_cache 1 } # Login user or commentator if ($http_cookie ~ * "comment_author | wordpress_ [a-f0-9] + | wp-postpass | wordpress_no_cache | wordpress_logged_in") {set $skip_cache 1;} location = / {index index.php index.html; try_files / index.php?$args / index.php?$args;} location / {index index.php index.html Try_files $uri $uri/ / index.php?$args;} location ~ ^ /\ .user\ .ini {deny all;} location ~\ .php$ {try_files $uri = 404; fastcgi_index index.php; fastcgi_pass 127.0.0.1 fastcgi_index index.php; fastcgi_pass 9000; fastcgi_cache tlanyan; fastcgi_cache_valid 200301 302 30m; fastcgi_cache_valid 404 10m Fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache_lock on; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;} location ~. (js | css | png | jpg | gif | swf | ico | pdf | mov | fla | zip | rar | jpeg) ${expires max; access_log off; try_files $uri = 404 }} the above configuration is valid for the latest version of Nginx test. For more information on configuration instructions, please refer to the official Nginx documentation. This is the answer to the question on how to use Nginx cache to speed up WordPress sites. I hope the above content can be of some help to you. If you still have a lot of questions to solve, you can follow the industry information channel for more related knowledge.
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.