1

We currently have nginx sitting in front of our puma app servers (serving rails apps). Recently we've separated out 'marketing' pages into it's own repo and app.

So essentially we have static content served by app deploy on the netlify, but we have our rails app take over once users are logged in.

Any advice how to set this one up? So we use one domain for both of these? Initially we were thinking to create a subdomain for static content like (static.mydomain.com) and serve everything from there, but that approach has major downsides (domain and subdomain don't have the same SEO).

Can nginx do some kind of url rewrite so our static app on netlify appears under our domain? Or has anyone solved this problem differently?

Update:

I was able to use suggestion from Josh and ended up with this :

server {

...

location ^~ /about { proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://yourdeployment.netlify.com/about; } }

Now however there are some resources (js/css/json) that netlify loads from roor url http://yourdeployment.netlify.com/somescrip-someshavalue.sj that my nginx is starting to get from mydomain.com .

Is there way I can intercept these or I have to manually add redirect rules as in add location block for each of the resources ?

Remember_me
  • 133
  • 4

1 Answers1

0

You should be able to serve the netlify app on a path if you want to by using proxy_pass in nginx.

A configuration like this should work:

server {
  # ...
  location ^~ /about {
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Real-IP $remote_addr;
    # remove the preceding "/about/" from the URL
    rewrite ^/about/(.*) /$1 break;
    # pass it on to the netlify app
    proxy_pass http://yourdeployment.netlify.com;
  }
}

The path can be whatever you want. If you wanted a subdomain to be used, you would set up a different server {} block with a server_name matching that subdomain and a location / {} with the proxy pass directive.

  • thanks for the response. So what you're saying that if users go to `www.mydomain.com/about` it will render the http://yourdeployment.netlify.com but url would show `www.mydomain.com/about` or would it show `http://yourdeployment.netlify.com` ? – Remember_me Jul 09 '20 at 00:13
  • The URL will show `www.mydomain.com/about`. However, all resource URLs served by `yourdeployment.netlify.com` should be changes do `www.mydomain.com`. – Tero Kilkanen Jul 09 '20 at 06:51