如何在LEMP / Laravel 5.8中为本地(DEV)环境正确设置多租户(子域)?

时间:2019-05-20 17:34:42

标签: laravel nginx subdomain dnsmasq

我正在使用PHP 7.1,NGINX和Laravel 5.8运行ubuntu 16.04。

我的目标是在我的本地(dev)环境中创建一个多租户应用。

根URL为myapp.com。我想从以下URL中检索:account1.myapp.comaccount2.myapp.com...,然后显示字符串account1account2...。< / p>

通过低谷后一些帖子:

  1. Use /etc/hosts to direct wildcard domain name
  2. How to put wildcard entry into /etc/hosts?
  3. Multi-Tenant Laravel on Ubuntu
  4. Wildcard in /etc/hosts file

我得知我应该:

  1. 安装和设置dnsmasq /etc/dnsmasq.conf (address=/myapp.com/127.0.0.1)
  2. Set the routes in Laravel to retrieve the subdomains
  3. 设置主机(127.0.0.1 myapp.com)
  4. 设置/etc/nginx/sites-available/myapp.com.conf (server_name *.myapp.com myapp.com;)

所有步骤之后, 网址myapp.com Route::get('/', 'HomeController@index');运作良好,但网址http://account1.myapp.com/仍然无法运作(无法访问该网站)

我不知道自己在做什么错。 一些帮助?

那是我到目前为止的代码:

路线

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 ...
...

0 个答案:

没有答案