首页 > 解决方案 > 在 nginx vps 主机上托管具有多个子域的 Laravel 应用程序

问题描述

我有一个 Ubuntu 18.04 LTS VPS,我正在托管一个 Laravel 应用程序,其论坛部分路由到子域。该站点的主要部分被路由到 TLD。

当我访问 www.example.com 时,我能够配置 Nginx 以提供我的主站点内容,但是,当我访问 forum.example.com 时,找不到该站点的 IP 地址

这是我的 Godaddy 配置:https ://pasteboard.co/IP3XM3n.png

这是我的 nginx 配置文件:

    listen 80;


    root /var/www/intransportal/public;
    index index.php index.html index.htm;

    server_name intransportal.com forum.intransportal.com;

      location @rewrite {
            rewrite ^/(.*)$ /index.php?_url=/$1;
        }

    location / {
            try_files $uri $uri/ @rewrite;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

这是我的路线



$domain = parse_url(config('app.url'), PHP_URL_HOST);
Route::domain('forum.'.$domain)->group(function() {
    Route::get('/threads/', 'ThreadsController@index');
    Route::get('/threads/create', 'ThreadsController@create');
    Route::get('/threads/{channel}/{thread}', 'ThreadsController@show');
    Route::delete('/threads/{channel}/{thread}', 'ThreadsController@destroy');
    Route::post('/threads', 'ThreadsController@store');
    Route::get('/threads/{channel}/{thread}/replies','RepliesController@index');
    Route::post('/threads/{channel}/{thread}/replies','RepliesController@store');
    Route::get('/threads/{channel}', 'ThreadsController@index');
    Route::patch('/replies/{reply}', 'RepliesController@update');
    Route::delete('/replies/{reply}', 'RepliesController@destroy');
    Route::post('/replies/{reply}/favorite', 'FavoritesController@store');
    Route::delete('/replies/{reply}/favorite','FavoritesController@destroy');
    Route::get('/', 'ThreadsController@index');
    Route::patch('/replies/{reply}', 'RepliesController@update');

});
Route::get('/','HomeController@index');
Auth::routes();
Route::get('profiles/{user}', 'ProfilesController@show')->name('profile');
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('photos', 'PhotosController');

如何将论坛的路由指向我的子域?

标签: phplaravelubuntu

解决方案


您想要CNAME子域的记录。

+-----------------------+
| Type    Name    Value |
+-----------------------+
| CNAME   forum   @     |
+-----------------------+

推荐阅读