I am running ubuntu 16.04 with PHP 7.1, NGINX and Laravel 5.8.
My goal is to create a multitenant app in my local (dev) environment.
The root url is myapp.com
. I want to retrieve from the URL: account1.myapp.com
, account2.myapp.com
, ...
and display back the string account1
, or account2
, ...
.
After passing trough some posts:
- Use /etc/hosts to direct wildcard domain name
- How to put wildcard entry into /etc/hosts?
- Multi-Tenant Laravel on Ubuntu
- Wildcard in /etc/hosts file
I've learned that I should:
- Install and setup dnsmasq
/etc/dnsmasq.conf (address=/myapp.com/127.0.0.1)
- Set the routes in Laravel to retrieve the subdomains
- Set the hosts (127.0.0.1 myapp.com)
- Set the
/etc/nginx/sites-available/myapp.com.conf (server_name *.myapp.com myapp.com;)
After all that steps,
the url myapp.com is working good Route::get('/', 'HomeController@index');
, but the url http://account1.myapp.com/, still not working (This site can’t be reached)
I can't figure out what I am doing wrong. Some help?
That is the code I have so far:
ROUTE
Route::domain('{account}.myapp.com/')->group(function ($account) {
return $account;
});
Auth::routes();
Route::get('/', 'HomeController@index');
/etc/hosts
127.0.0.1 myapp.com
/etc/nginx/sites-available/myapp.com.conf
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;
}
/etc/dnsmasq.conf
# Configuration file for dnsmasq.
#
address=/myapp.com/127.0.0.1
# Format is one option per line, legal options are the same ...
...