title: How to properly setup multitenant (subDomains) in a LEMP/Laravel 5.8 for local (DEV) environment?
body: <p>I am running ubuntu 16.04 with PHP 7.1, NGINX and Laravel 5.8.</p>
  
  <p>My goal is to create a multitenant app in my local (dev) environment.</p>
  
  <p>The root url is <code>myapp.com</code>. I want to retrieve from the URL: <code>account1.myapp.com</code>, <code>account2.myapp.com</code>, <code>...</code> and display back the string <code>account1</code>, or <code>account2</code>, <code>...</code> .</p>
  
  <p>After passing trough some posts:</p>
  
  <ol>
  <li><a href="https://askubuntu.com/questions/743050/use-etc-hosts-to-direct-wildcard-domain-name">Use /etc/hosts to direct wildcard domain name</a></li>
  <li><a href="https://stackoverflow.com/questions/20446930/how-to-put-wildcard-entry-into-etc-hosts">How to put wildcard entry into /etc/hosts?</a></li>
  <li><a href="https://medium.com/@dlimars/configura%C3%A7%C3%A3o-de-subdom%C3%ADnios-local-apache-dnsmasq-laravel-6fcdcbea5bb6?fbclid=IwAR1gJEoH_7LySNj4lVpeyVXX_9wnbzUKksVwp5XgXB_SMZTQHVznsbcUGa8" rel="nofollow noreferrer">Multi-Tenant Laravel on Ubuntu</a> </li>
  <li><a href="https://unix.stackexchange.com/questions/3352/wildcard-in-etc-hosts-file">Wildcard in /etc/hosts file</a></li>
  </ol>
  
  <p>I've learned that I should:</p>
  
  <ol>
  <li>Install and setup dnsmasq <code>/etc/dnsmasq.conf (address=/myapp.com/127.0.0.1)</code></li>
  <li><a href="https://laravel.com/docs/5.8/routing#route-group-sub-domain-routing" rel="nofollow noreferrer">Set the routes in Laravel to retrieve the subdomains</a></li>
  <li>Set the hosts (127.0.0.1 myapp.com)</li>
  <li>Set the <code>/etc/nginx/sites-available/myapp.com.conf (server_name *.myapp.com myapp.com;)</code></li>
  </ol>
  
  <p>After all that steps,
  the url myapp.com is working good <code>Route::get('/', 'HomeController@index');</code>, but the url <a href="http://account1.myapp.com/" rel="nofollow noreferrer">http://account1.myapp.com/</a>, still not working (This site can’t be reached)</p>
  
  <p>I can't figure out what I am doing wrong.
  Some help? </p>
  
  <p>That is the code I have so far:</p>
  
  <h2>ROUTE</h2>
  
  <pre><code>Route::domain('{account}.myapp.com/')-&gt;group(function ($account) {
      return $account;
  });
  
  Auth::routes();
  
  Route::get('/', 'HomeController@index');
  </code></pre>
  
  <h2>/etc/hosts</h2>
  
  <pre><code>127.0.0.1       myapp.com
  </code></pre>
  
  <h2>/etc/nginx/sites-available/myapp.com.conf</h2>
  
  <pre><code>server {
      listen 80;
      server_name *.myapp.com myapp.com;
      root /var/www/vhosts/myapp.com/public;
  
      index index.html index.htm index.php;
  
      charset utf-8;
  
      location / {
          try_files $uri $uri/ /index.php?$query_string;
      }
  
      location = /favicon.ico { access_log off; log_not_found off; }
      location = /robots.txt  { access_log off; log_not_found off; }
  
      access_log off;
      error_log  /var/log/nginx/myapp.com-error.log error;
  
      error_page 404 /index.php;
  
      sendfile off;
  
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_intercept_errors on;
          fastcgi_buffer_size 16k;
          fastcgi_buffers 4 16k;
      }
  
      location ~ /\.ht {
          deny all;
      }
  
      client_max_body_size 1000m;
  }
  </code></pre>
  
  <h2>/etc/dnsmasq.conf</h2>
  
  <pre><code># Configuration file for dnsmasq.
  #
  
  address=/myapp.com/127.0.0.1
  
  # Format is one option per line, legal options are the same ...
  ...
  </code></pre>