NGINX - 重写某些 URL 以服务 Wordpress [英] NGINX - rewriting certain URLs to serve Wordpress
问题描述
我正在慢慢地将运行在 NGINX 服务器上的现有 Drupal 站点转换到 Wordpress.这意味着,目前,我希望一些 URL 为 Wordpress 服务,而其他 URL 为 Drupal 服务.
I'm slowly transitioning my existing Drupal site, running on a NGINX server, to Wordpress. This means that, at the moment, I want some URLs to serve Wordpress, while others serve Drupal.
我现有的 NGINX 服务器配置,非常适合为 Drupal 页面提供服务,如下所示:
My existing NGINX server configuration, which works perfectly to serve Drupal pages, is as follows:
server {
limit_conn gulag 10;
listen 80;
server_name www.mysite.com;
root /home/mysite/public_html;
index index.php index.html;
include /etc/nginx/configs/drupal.conf;
} # end of server
如何修改它,例如,如果我尝试访问 http://www.mysite.com/pageX.html,NGINX 会使用该 URI 提供 Wordpress 页面(并包含 Wordpress.conf 文件而不是 Drupal.conf 文件)?但是所有其他 URL 将继续由 Drupal 使用上述配置提供服务.
How would modify this so that, for example, if I tried to access http://www.mysite.com/pageX.html, NGINX would serve the Wordpress page with that URI instead (and include a Wordpress.conf file instead of the Drupal.conf file)? But all other URLs would continue to be served by Drupal using the configuration as above.
我相信它涉及在位置块内设置一个新的 root 变量,但还没有取得任何成功.
I believe it involves setting a new root variable inside a location block, but haven't had any success with it yet.
我的 Wordpress 安装在/home/mysite/wordpress/
My Wordpress installation is at /home/mysite/wordpress/
谢谢.
推荐答案
只需将您的 include
指令放入一个位置,然后重置根:
Just put your include
directive into a location, and reset the root:
server {
limit_conn gulag 10;
listen 80;
server_name www.mysite.com;
root /home/mysite/public_html;
index index.php index.html;
location /pageX.html {
root /home/mysite/wordpress/;
include /etc/nginx/configs/wordpress.conf;
}
} # end of server
虽然我认为重置 root 不是最好的选择.
Although I think resetting the root is not the best choice here.
当然,您可以对位置使用匹配的正则表达式.
And of course you can use a matching regex for the location.
这篇关于NGINX - 重写某些 URL 以服务 Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!