Nginx with Wordpress and a Nodejs app (Mean) in the same VPS (Ubuntu)

Posted August 13, 2016 5.2k views


I’m running a nodejs app in the domain and I want to run a Wordpress with Nginx in

I started with a “one click install” using the Mean application and installing the nodejs app in the port 9000
Then, I’m following this link to install Nginx and Wordpress:

I guess, in the Nginx file config, I should create one location for /blog (linked to Nginx+Wordpress in port 80) and another one for “/” (linked to the node app in port 9000), but doesn’t work. load properly the nodejs app
But, is not loading wordpress.

Am I doing something wrong ?

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

root /var/www//html;

index index.php index.html index.htm;

# Make site accessible from http://localhost/


location /blog {

                try_files $uri $uri/ /index.php?q=$uri&$args;


error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
                root /usr/share/nginx/html;

location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

location /{

        proxy_pass http://localhost:{9000};

        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;



These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

It can be a bit tricky to get your proxy_pass to not include the subdirectory path under it. This thread provides some useful examples of running a node.js all along side WordPress in much the way you want to. After some trial and error this post provided a workable solution like the following:

 server {
listen 80;
access_log /var/log/nginx/nginx-access.log;
error_log /var/log/nginx/nginx-error.log;
root /home/user/example;

# pass the request to the node.js server with the correct headers and much more can be added, see nginx$
location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
      proxy_pass http://localhost:9000;
      proxy_redirect off;
     location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|ttf|woff|eot|svg)$ {
        alias   /home/user/example/public;

location @blog {
  rewrite ^/blog(.*) /blog/index.php?q=$1;
location /blog {
    index index.php;
    try_files $uri $uri/ @blog;
    alias /home/user/example/blog;

     location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;

        #if (!-e $request_filename)
        #   rewrite ^(.+)$ /index.php?q=$1 last;
} }