WordPress站点怎么加速 Nginx缓存可以吗

小七 52 0

  客开通lái ,主要记xué习和使yòngchéng中遇dàodewèn及解决方àn 。wén章风格偏向乐,因访fǎngwènliàng较少,tái1核1Gdevps足chēngwǎngzhàndezhèngyùn行。

  后láiběnzhàn三个面 ,这三个面应该duì有上外wǎngqiúdewǎnghěn有帮助,gěiběnzhànláihěndeliàng。běnzhànyòngdeWordPresschéng序,尝shìānhuǎncúnjiàn(super cache, w3 total cache等)加yùn行 ,但shìpèidevps依然难支持这么de访fǎngwènliàng 。通过日志dào随着访fǎngwènliàngde增加 ,php-fpm进chéng增多,Mysqldejiē线xiànchéng增多,jiē着出现OOM ,然后系统kill掉占yòngcúndeMysql进chéng,shìwǎngzhàn503dàng机模式。

  买更好devpsnéng解决访fǎngwènliàngdewèn,但shì要花更多deqián。zuòwèi个技shùzhái ,首先想dàode当然shì榨干现有机器láichēngliàng 。zuòdeshì包括qièdàoWordPress性néng更好deGhost,cān考:尝shìGhost 。但shìxiāngduìWordPress,Ghostdeshēng态远没有那么成shú ,最终放弃了。

  左思右想下,终极解决办法shìyòngNginxhuǎncún,最初dewéncān考:Nginxpèizhìfastcgi cache。fastcgi_cachede好处shìyòngdeqǐngqiúyòng后端php-fpmdào ,直jiē发送huǎncúnde静态面,度上shuǎi种WordPress插jiàn好几条街!xiāng之下wordpressde种插jiàn还要zhí行php,避免不了访fǎngwèn数据库 ,弱爆了!

  从使yòng了nginxhuǎncún ,wǎngzhàn平稳yùn行,再没有出现过dàngdexiàng 。同时vpsdecpu和内cúnyòng率直线xiàn下降,再担心vpsdepèizhìwèn ,感觉再lái10bèiliàngchēng住!

  因wèinginx稳如狗deyàn,所现在duì客类读多写少de产品都shì强推nginxhuǎncún(fastcgihuǎncún或者proxyhuǎncún)。鉴néngdàoxiēwǎng友,现贴出 /etc/nginx/nginx.conf pèizhìwénjiànwǎngcān考(包含ssl设zhì和gzip分):

  # wénjiàn: /etc/nginx/nginx.conf

  # For more information on configuration, see:

  # * Official English Documentation:

  # * Official Russian Documentation:

  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;

  # sslpèizhì

  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";

  # qǐng按照deqiú更改

  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 pèizhì

  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

  # for more information.

  include /etc/nginx/conf.d/*.conf;

  }

  yòngWordPresszhàndewǎngzhànpèizhìwénjiàn(/etc/nginx/conf.d/tlanyan.conf):

  server {

  listen 80;

  listen [::]:80;

  server_name tlanyan.me; # qǐng换成demíng

  rewrite ^(.*) permanent;

  }

  server {

  listen 443 ssl http2;

  listen [::]:443 ssl http2;

  server_name tlanyan.me; # qǐng换成demíng

  charset utf-8;

  ssl_certificate /etc/nginx/conf.d/tlanyan.pem; # qǐng换成dezhèng书和密钥

  ssl_certificate_key /etc/nginx/conf.d/tlanyan.key;

  set $host_path "/var/"; # qǐng改成de路径

  access_log /var/log/nginx/tlanyan.access.log main buffer=32k flush=30s;

  error_log /var/log/nginx/tlanyan.error.log;

  root $host_path;

  # huǎncún标记

  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;

  }

  # 登yòng或发表pínglùn

  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: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_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;

  }

  }

  上述pèizhìduìxīndeNginx测shìxiào ,xiángpèizhì指令qǐngcān考Nginx官方wén档。

  申qǐngchuàngdào,分xiǎngchuàng好点子 。点击处,gòng同探讨chuàngxīn机遇!

标签: 已有网站怎么seo 昆明seo和网络推广 seo页面优化平台都选d火12星 seo排名4助力 火 星 青岛网站优化seo

发表评论 (已有0条评论)

还木有评论哦,快来抢沙发吧~