同一Nginx服务器博客上的静态页面和Wordpress

时间:2019-07-16 21:26:38

标签: wordpress nginx

我有一个静态网站,该网站使用从Wordpress通过API提取的数据进行渲染,并希望在网站的根级别(即//posts/the-post等)提供静态生成的页面),但Wordpress仍会在wp-adminwp-content等处进行响应。

但是我在Wordpress目录中也有其他路由(例如/assets),并且我希望将可用静态应用程序路由未处理的任何内容推送到Wordpress。

此外,我还有几个具有可用路由(/thisplugin/thatplugin)的插件,这些插件也需要继续由Wordpress处理。

在下面的配置中,我非常接近,wp-admin有效,wp-content有效(尽管我必须声明),assets有效(虽然我必须声明),但是我的插件网址没有。

我知道^/wp-位限制了@wp块可以响应的范围,这破坏了插件路由。但是,如果我不包括在内,则wp-admin只会重定向到主页。

这是配置。有人可以在这里看到我在做什么错吗?

server {

  listen 443 http2 ssl;
  server_name website.com www.website.com;

  # Include SSL configutation
  include snippets/ssl-website.com.conf;
  include snippets/ssl-params.conf;

  # Set root directory
  root /var/www/next/source/serve;

  # # Access and error logs
  access_log /var/log/nginx/next_access.log;
  error_log /var/log/nginx/next_error.log;

  # # GZIP
  gzip on;
  gunzip on;
  gzip_disable "msie6";
  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_buffers 16 8k;
  gzip_types text/plain text/xml text/javascript application/x-javascript application/javascript text/css image/svg+xml application/x-font-ttf font/opentype application/json application/xml application/xml+rss;

  # Don't allow access to htaccess-type files or dot files
  location ~ /\.ht { deny all; }
  location ~ /\. { deny  all; access_log off; log_not_found off; }
  # Don't log access to favicon or robots.txt

  # Set long expiry on static files
  location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|html)$ {
    access_log off;
    log_not_found off;
    expires 365d;
    add_header Cache-Control "public, max-age=31536000";
  }

  # Allow fonts to be served by CDN
  location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
    add_header Access-Control-Allow-Origin "*";
  }

  location @wp {
    rewrite ^/wp-(.*) /index.php?q=$1;
  }

  location ^~ /wp-content/ {
    alias /var/www/wordpress/wp-content/;
    break;
  }

  location ^~ /assets/ {
    alias /var/www/wordpress/assets/;
    break;
  }

  location ~ \.php$ {
    root /var/www/wordpress;
    index index.php index.html index.htm;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  }

  location / {
    try_files $uri $uri/ @wp;
  }
}

0 个答案:

没有答案