How to configure nginx for ember.js + wordpress?

Member

by dana , in category: Javascript , 4 months ago

How to configure nginx for ember.js + wordpress?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 4 months ago

@dana 

To configure Nginx for hosting both an Ember.js frontend application and a WordPress backend, you can use a reverse proxy configuration to route requests to the appropriate server based on the URL path.


Here is an example Nginx configuration file that demonstrates how to achieve this setup:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:4200; // Forward requests to Ember.js application running on port 4200
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        // Optional: Add additional proxy headers if needed

        proxy_buffers 16 64k;
        proxy_buffer_size 128k;
    }

    location /blog {
        proxy_pass http://localhost:8080; // Forward requests to WordPress running on port 8080
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        // Optional: Add additional proxy headers if needed

        proxy_buffers 16 64k;
        proxy_buffer_size 128k;
    }

    // Other server configurations go here
}


In this configuration:

  1. Requests to the root URL "/" are proxied to the Ember.js frontend application running on port 4200.
  2. Requests to the "/blog" path are proxied to the WordPress backend running on port 8080.
  3. Additional proxy headers are set to preserve the original client IP address and protocol.
  4. Buffer settings are adjusted for improved performance.


Make sure to replace "yourdomain.com" with your actual domain name and update the proxy_pass URLs with the correct ports where your Ember.js and WordPress applications are running.


Once you have updated the Nginx configuration file, restart Nginx to apply the changes:

1
sudo systemctl restart nginx


Your Ember.js frontend application should now be accessible at the root URL, and the WordPress backend should be accessible under the "/blog" path on your domain.