提高WordPress站点的访问速度的核心方法

                       

很多WordPress站长抱怨WordPress网站速度太慢。因此作为十安知识分享者小安不能忍。决定把提高WordPress站点的访问速度的核心方法分享给大家。

提高WordPress站点的访问速度的核心方法

WordPress由于是动态网站,随着网站的数据越多,访问的人数越多,他程序执行的任务也自然就越多,所以所谓的WordPress站点卡由此而生,为了让小白逃离盲区,我必须强调一点,那不是卡,是数据量以及访问量过大导致的延迟(众所周知双11的时候阿里的服务器运维也是胆战心惊的,难道说阿里的网站也是卡吗?)。

提高WordPress站点的访问速度,可以让WordPress站点使用Nginx缓存加速。具体操作如下:

/etc/nginx/nginx.conf 配置文件供网友参考(包含ssl设置和gzip部分):

# 文件: /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_formatmain'$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.logmain buffer=32k flush=30s;server_tokensoff;client_max_body_size 100m;sendfileon;tcp_nopushon;tcp_nodelayon;keepalive_timeout65;types_hash_max_size 2048;include/etc/nginx/mime.types;default_typeapplication/octet-stream;# ssl配置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.7ssl_stapling_verify on; # Requires nginx => 1.3.7add_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";# 请按照自己的需求更改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;fastcgi_cache_valid 200 301 302 10h;fastcgi_cache_valid 404 10m;fastcgi_ignore_headers Expires Set-Cookie Vary;# gzip 配置gzip on;gzip_min_length1k;gzip_buffers4 16k;gzip_comp_level 7;gzip_typestext/csstext/plaintext/javascriptapplication/javascriptapplication/jsonapplication/x-javascriptapplication/xmlapplication/xml+rssapplication/xhtml+xmlapplication/x-font-ttfapplication/x-font-opentypeapplication/vnd.ms-fontobjectimage/svg+xmlimage/x-iconapplication/rss+xmlapplication/atom_xmlimage/jpegimage/gifimage/pngimage/iconimage/bmpimage/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;}以及用于WordPress站点的网站配置文件(/etc/nginx/conf.d/tlanyan.conf):server {listen 80;listen [::]:80;server_name www.tlanyan.me tlanyan.me; # 请换成自己的域名rewrite ^(.*) https://$server_name$1 permanent;}server {listen443 ssl http2;listen[::]:443 ssl http2;server_name www.tlanyan.me tlanyan.me; # 请换成自己的域名charset utf-8;ssl_certificate /etc/nginx/conf.d/tlanyan.pem;# 请换成自己的证书和密钥ssl_certificate_key /etc/nginx/conf.d/tlanyan.key;set $host_path "/var/www/tlanyan";# 请改成自己的路径access_log/var/log/nginx/tlanyan.access.logmain buffer=32k flush=30s;error_log /var/log/nginx/tlanyan.error.log;root$host_path;# 缓存标记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;}# 登录用户或发表评论者if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {set $skip_cache 1;}location = / {indexindex.php index.html;try_files /index.php?$args /index.php?$args;}location / {indexindex.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_pass127.0.0.1:9000;fastcgi_cache tlanyan;fastcgi_cache_valid 200 301 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_paramSCRIPT_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;}}上述配置对最新版的Nginx测试有效,详细配置指令请参考Nginx官方文档。

更多WordPress技术文章请关注WordPress建站知识其它相关文章!

以上就是《提高WordPress站点的访问速度的核心方法》的详细内容,更多知识请关注十安知识网其它相关文章!

本文链接:https://www.shianvip.com/article/1965.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 86345@qq.com 举报,一经查实,本站将立刻删除。

发表评论

电子邮件地址不会被公开。 必填项已用*标注