wordpress - 使用 Nginx 通过博客域仅提供 Wordpress API
问题描述
我想使用 WP API 将我的 WP 博客集成到非 WP 站点中。
我的博客目前位于,site.com/blog
因此 API 托管在site.com/blog/wp-json
我的非 WP 网站位于site.com
当用户访问site.com/blog
或site.com/blog/<slug>
我想为非 WP 网站提供服务时,但如果我访问site.com/blog/wp-json/*
或site.com/blog/wp-admin
(基本上任何带有 的/blog/wp-*
)由 Wordpress 提供服务。
我正在使用 Nginx 并进行此设置sites-available
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
rewrite ^/([^/]+)\/([^/]+)/[0-9]+.html$ /vinyl/$1-$2/ permanent;
#add_header Cache-Control 'no-store';
}
location ~ /blog/.*\.php$ {
root /var/www/websitename;
index index.php index.html index.htm;
set $php_root /var/www/websitename/blog;
include /etc/nginx/fastcgi_params;
try_files $uri =404;
fastcgi_read_timeout 180;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location /blog {
root /var/www/websitename;
index index.php index.html index.htm;
set $php_root /var/www/websitename/blog;
try_files $uri $uri/ /blog/index.php$is_args$args;
}
解决方案
location ~ ^/blog/wp-.*$ {
#go to wordpress
}
location ~ ^/blog {
#go to non-wordpress
}
按照这个顺序,任何以 /blog/wp-ANYTHING 开头的东西都会进入 wordpress。并且如果没有被这个位置括号占用,如果它以/blog开头,它将转到非wordpress
推荐阅读
- flutter - 如何在 Flutter 上的 SingleChildScrollView 中放置 StickyGroupListView?
- javascript - 使用 history.block 后 history.push 不起作用
- python-3.x - PermissionError:[Errno 13] 权限被拒绝:使用 Python 和 Flask 上传文件时
- python - Pandas dataframe col - 将“__”更改为“_”和“_”更改为“”的有效方法?
- java - java中如何记录每道题的时间和持续时间?
- html - 使用 CSS 添加背景图像
- php - 如何在 Laravel 8 的默认 Jetstream 注册页面上添加字段
- tensorflow - 在 TF2 中修剪 ML 模型
- oracle - ROW_NUMBER 的性能
- reactjs - url重定向成功,但在react js typescript上使用重定向时未调用组件