Magento WordPress Integration NginxWordPress Integration

« Back to Magento WordPress Integration

Magento 2 now supports Nginx and includes a usable Nginx config file with the default installation called nginx.conf.sample. It is possible to include this file directly into your main Nginx conf file to get Magento working.

The nginx.conf.sample file doesn't cover WordPress but it is easy to get WordPress up and running on Nginx.

The below code extract should go inside your main server block but after you have included nginx.conf.sample. It assumes that you have installed WordPress in either pub/wp or /wp.

location /wp/ {
  index index.html index.php;
  try_files $uri $uri/ /wp/index.php?q=$uri&args;

  location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  /wp/index.php;
    include        fastcgi.conf;
  }
}

Here is a full working Nginx config for Magento 2 with WordPress installed in pub/wp.

upstream fastcgi_backend {
  server  127.0.0.1:9000;
}

server {
  listen 80;
  
  # Magento 2 base URL
  server_name m2.latest.composer.fp.com;
  
  # Magento 2 root directory
  set $MAGE_ROOT /home/magento2/html;
  
  set $MAGE_DEBUG_SHOW_ARGS 1;

  include /home/magento2/html/nginx.conf.sample;

  # WordPress is installed in pub/wp
  location /wp/ {
    index index.html index.php;
    try_files $uri $uri/ /wp/index.php?q=$uri&args;

    location ~ \.php$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  /wp/index.php;
      include        fastcgi.conf;
    }
  }
}