Setup Local Dev with DOT Test

This is not Rails tutorial, but i use Rails references. Swap it with what ever the framework you use. How ever this setup is for Linux.

Not every project can simply rely on rails s for local development. This is specially true if you are working on a SaaS application that is using sub-domains for tenants. Today I am going to share with you how I have configured my local development environment to serve project using .test TLD.

The setup is as follows…

I assume you have a (Rails) project in /home/user/client/project.

DOT Test to localhost

There are many ways you can do this. But I believe the easiest way is to use dnsmasq.

#~ sudo apt-get install dnsmasq

If you are in Ubuntu you would need to update NetworkManager config. This is because NetworkManager it self uses dnsmasq which conflicts with our interests. Open up /etc/NetworkManager/NetworkManager.conf and comment out the line that reads dns=dnsmasq. Then restart the service

#~ sudo restart network-manager

Then you need to configure dnsmasq to listen to local DNS queries. Edit /etc/dnsmasq.conf and add listen-address= to the file.

Next we need to tell dnsmasq to resolve .test to localhost. To do this create a new file /etc/dnsmasq.d/test with content address=/test/

Now we are good. What we need to do is to install and setup Nginx.

Nginx Reverse Proxy

If you wanted to setup local environment to host .test domains, the chances are you need to configure Nginx or Apache for the task as well. I don’t use Apache. So here is an example how to install and configure Nginx to serve a Rails application.

Many developers I know already know how to setup and configure Nginx, so I kept it for last.


First of all, lets install it!

#~ sudo apt-get install nginx

Can’t get any simple than that, could it!

Project Configuration

I am assuming your project uses sub-domains. Some thing like a SaaS application with tenants served through sub-domains.

Create a file in

upstream projecttest {
  server localhost:3000 max_fails=3 fail_timeout=600;

server {
  listen 80;
  server_name *.project.test;

  root /home/user/client/project/public;

  try_files $uri/index.html $uri @projecttest;

  location @projecttest {
    proxy_pass http://projecttest;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;

Here projecttest can be what ever you like. I use the naming format <project-name><tld>. Some use app. Its up to you!


Thats it… no cd to your project folder and run rails s and visit your app… www.project.test or any of its sub domains.