NGINX - rewriting certain URLs to serve Wordpress

2019-08-28 05:00发布

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.

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

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.

I believe it involves setting a new root variable inside a location block, but haven't had any success with it yet.

My Wordpress installation is at /home/mysite/wordpress/

Thanks.

1条回答
Fickle 薄情
2楼-- · 2019-08-28 05:50

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

Although I think resetting the root is not the best choice here.

And of course you can use a matching regex for the location.

查看更多
登录 后发表回答