如何在实时服务器上部署静态子域+通配符子域laravel应用?

时间:2019-09-24 17:54:25

标签: php laravel deployment subdomain wildcard-subdomain

在我的laravel项目应用中,我有以下路线。 app.client.net用于用户注册,通配符子域*.client.net用于登录的用户。 Route.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::group(['domain' => 'app.client.net'], function(){
    Route::get('/', function () {
        if (auth()->check()) {
            return redirect('http://'.session('subdomain').'.client.net/home');
        }       
        return view('welcome');
    })->name('homepage');   
    Route::get('/register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    Route::post('/register', 'Auth\RegisterController@register');
    Route::get('/login', 'Auth\LoginController@showLoginForm')->name('login');
    Route::post('/login', 'Auth\LoginController@login')->name('login');
    Route::get('/setupCompany', 'CompanyController@setupCompanyForm')->name('setupCompanyForm');
    Route::post('/setupCompany', 'CompanyController@setupCompany')->name('setupCompany');
    Route::get('/register/verify', 'CompanyController@verfiy')->name('registerVerify');

});

Route::group(['domain'=> '{subdomain}.client.net', 'middleware' => 'checkSubdomain'],function () {
    Route::get('/', 'Auth\CompanyLoginController@showLoginForm')->name('companyLogin');
    Route::post('/', 'Auth\CompanyLoginController@login')->name('companyLogin');

    Route::group(['middleware' => 'customAuth'],function(){         
        Route::get('/home', 'HomeController@index')->name('home');
        Route::post('/logout', 'Auth\LoginController@logout')->name('logout');
        Route::post('/inviteClient', 'HomeController@inviteClient'); //ajax req
        Route::get('/profile', ['as' => 'profile.edit', 'uses' => 'ProfileController@edit']);
        Route::put('profile', ['as' => 'profile.update', 'uses' => 'ProfileController@update']);
        Route::put('profile/password', ['as' => 'profile.password', 'uses' => 'ProfileController@password']);

        Route::get('/getClients', 'HomeController@clients'); //ajax req

    });
});


这在localhost上运行良好,但是当我通过在服务器上部署app.client.net子域并在其中部署项目将其部署到活动服务器上时,通配符子域{subdomain}.client.net无法正常工作。 当我转到app.client.net时,它可以正常工作,但是当我访问通配符子域时,例如abc.client.net,则出现以下错误。

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

如何配置它,以便静态子域和通配符子域可以在服务器子域上工作。 或者我必须分别在服务器app.client.net*.client.net上创建两个子域,一个用于静态子域,另一个用于通配符子域,并在app.client.net服务器子域和通配符子域上部署静态子域路由分别在*.client.net服务器通配符子域上路由? 预先感谢。

0 个答案:

没有答案