Skip to content

Home

Development

IDEs

API Explorer

Releases

Release notes

Martini Runtime

Martini Desktop

Martini Online

Feature requests

Bug reports

Proxying to a domain

At times, you may find the default URL of your applications hard to read, too long to remember, or misleading to your clients. In cases like these, (especially for applications intended for public-use), it pays to proxy the URL in favor of something shorter and more intuitive. This page will guide you on how to proxy your endpoints so clients can access your Martini-hosted APIs1 or web pages via friendlier URLs.

Instructions may or may not be applicable depending on your own setup

The procedures in this guide are based on a particular set of assumptions. Depending on your configuration, you may have to adjust some of the steps below.

Premise

The goal is to port an application accessible at https://integrations.torocloud.com/api/careers/account/create to https://my-careers.com/account/create.

Before proxying the domain

The steps below assume that a proxy server like NGINX is running in front of Martini. Full access to both Martini and the NGINX server is needed. In order to proxy the URL, we will create a proxy URL configuration in the proxy server.

Procedures

  1. Add a CNAME record to your domain's DNS records, pointing the proxy domain to the original one.

    Name Type Value
    my-careers.com CNAME integrations.torocloud.com
    integrations.torocloud.com A 192.0.2.23

    The original domain is integrations.torocloud.com and the intended proxy for it is my-careers.com. When creating the DNS entry, you have two options:

    • Create an A record pointing to the same IP address as integrations.torocloud.com.
    • Create a CNAME record pointing to integrations.torocloud.com.

    The latter is preferable over the former because you won't have to update the IPv4 value of the my-careers.com record if integrations.torocloud.com's IPv4 address changes.

  2. Create the NGINX configuration files.

    The sample configuration below will map the URL integrations.torocloud.com/api/careers to my-careers.com, treating https://my-careers.com as the root path:

     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
    35
    36
    37
    38
    39
    40
    server {
      listen 80;
    
      server_name my-careers.com
    
      location / {
        return         301 https://$server_name$request_uri;
      }
    
      include  /etc/nginx/standard_error_page.conf;
    }
    server {
      listen 443;
    
      server_name my-careers.com
    
      ssl on;
      ssl_certificate       /datastore/vhosts/ssl-certs/my-careers.com.crt;
      ssl_certificate_key   /datastore/vhosts/ssl-certs/my-careers.com.key;
    
      location /assets/ {
          proxy_pass      http://APP_SERVER:APP_PORT1/careers/;
      }
    
      location / {
           proxy_pass                 http://APP_SERVER:APP_PORT1/api/careers/;
           proxy_set_header           X-Forwarded-Host $host;
           proxy_set_header           X-Forwarded-Server $host;
           proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header           X-Forwarded-Port   80;
           proxy_set_header           Host $host;
    
           proxy_redirect             http://APP_SERVER:APP_PORT1/api/careers/ http://APP_SERVER:APP_PORT1/;
           proxy_connect_timeout      240;
           proxy_send_timeout         240;
           proxy_read_timeout         240;
           }
    
      include  /etc/nginx/standard_error_page.conf;
    }
    

    As you may have noticed, the /assets directory is also proxied. Files here are stored in the careers/web directory.

    1
    2
    3
    location /assets/ {
        proxy_pass      http://APP_SERVER:APP_PORT1/careers/;
    }
    

    The root path / also proxies the /api/careers path from the original request:

    1
    2
    location / {
         proxy_pass                 http://APP_SERVER:APP_PORT1/api/careers/;
    

    Disabling access to the original URL

    With the above configuration, the web UI should be available on both integrations.torocloud.com/api/careers and my-careers.com. However, to restrict access to the original URL, we can set up a redirect in the proxy server as shown below:

    1
    proxy_redirect             http://APP_SERVER:APP_PORT1/api/careers/ http://APP_SERVER:APP_PORT1/;
    
  3. After saving the NGINX configuration, reload NGINX and try to access the URL. The image below shows that the URL is now my-careers.com.

After proxying a domain