Redirect a subdirectory to another server while keeping the domain name

I have a working website under the domain domain.tld. We want to add an external service to it in such way we have domain.tld/blog but install it on another server so we don’t touch anything on this old (but working) one.

Is it possible to do on Fly.io?

My suggestion would be having a reverse proxy app.

Put your domain on the reverse proxy app and let it decide where to route to. You could reverse proxy using any generic reverse proxy such as minx that will redo the entire request on the other app and serve it to your end user or your could let your reverse proxy be very simple and use fly-replay so our proxy will take care of it:

Hi @lubien

Thanks for the reply. Do you have some guide or example on how to set up a reverse proxy app on Fly? I’m totally new to this and would appreciate any help.

Thanks

Below is a sample that may help you get started. It also demonstrates the common problem that you will see: links to scripts, stylesheets, images and even other pages need to either be aware of the fact that they are running under a subdirectory or be relative URLs. If you are the author of the app, this shouldn’t be a big problem, otherwise you may be able to get what you need using Module ngx_http_sub_module.

# syntax = docker/dockerfile:1

FROM nginx:latest

COPY <<-"EOF" usr/share/nginx/html/index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Hello World!</title>
  </head>
  <head>
    <h1>Hello World!</h1>
  </head>
</html>
EOF

COPY <<-"EOF" /etc/nginx/conf.d/default.conf
server {
  listen 8080;
  listen [::]:8080;
  server_name localhost;

  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
  }

  location /fly {
    proxy_ssl_server_name on;
    proxy_pass https://fly.io/;
  }

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

EXPOSE 8080

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.