When I migrate my wordpress-es to VPS, Apache was the default setup.

Problem: I wanted to run some Node.js apps in the same VPS, but node requires nginx.

Hence, I configured my VPS to run both Apache and Nginx.

That’s possible, when you make nginx a reverse proxy server.

The plan is as such:

  • nginx listens to port 80
  • nginx 1st server block is configured for node app at port 8021
  • nginx 2nd server block is configured to proxy to apache at port 8011
  • apache listen to port 8011
  • apache’s virtual hosts listen to port 8011

The details and a sample of the .conf files as follows. My scenario is using and


There are 2 server blocks, which I put in 2 seperate conf files: and apache-proxy.conf.

```nginx /etc/nginx/sites-available/
# Node server block
server {
listen 80;

        root  /var/www/;
        index   index.html index.htm;


        # temp for serving static
        location / {
          try_files $uri $uri/ /index.php;

        # Proxy to node app
        # Uncomment and remove the temp above if your node app is setup at port 8021
        #location / {
        #  proxy_pass http://localhost:8021;
        #  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;
} ```

Note: You should setup your node app and listen on 8021. In the meanwhile (testing), you can put a dummy index.html in /var/www/

```nginx /etc/nginx/sites-available/apache-proxy.conf
# Apache server block
# Proxy to 8011 which Apache is listening to
server {
listen 80 default_server;

        location / {

                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $host;
                proxy_pass http://localhost:8011;


         location ~ /\.ht {
                deny all;
} ```

Enable the nginx conf with these commands:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/apache-proxy.conf /etc/nginx/sites-enabled/apache-proxy.conf


For apache, you need to change the port file to listen to 8011.

```apache /etc/apache2/ports.conf
Listen 8011

# As per default configuration ```

Below is a sample of a virtual host file. You need to change for all. The change is again on the listening port.

```apache /etc/apache2/sites-available/
<VirtualHost *:8011>
# as per your configuration

## Restart

With that, restart each service with apache first, then nginx.

sudo service apache restart
sudo service nginx restart

Now, you if you go to, it should work, and it is because nginx is proxying nicely to apache.

You can also go to, which is directly to apache.

And of course, you can now write your node app at

I referenced from some of Digital Ocean guides:




Back to Home