Linux服务器,laravel配置问题

时间:2019-09-26 13:19:53

标签: php ajax laravel server apache2

当前,我正在基于Linux设置新服务器,安装了apache2,MySQL,phpmyadmin等。

用git安装了我的Laravel项目,除了向服务器发出的一些请求外,其他一切似乎都运行良好。

目前,我的/ var / www /文件夹结构为:

-/var/www
--- /home
--- /laravel

当用户通过http://server.xxxxxxx.com/访问服务器时,将重定向到/ home,其中有一个登录页面,基本上是Web应用程序的外观。

当用户转到http://server.xxxxxxx.com/erp/时,他将被重定向到/laravel/public目录。

所有加载情况良好,应用程序运行正常,但是AJAX请求到处都失败。

每个AJAX请求均以错误结束。例如:

  

在此服务器上找不到请求的URL / pie-data

我已经尝试了所有可以在网络上找到该URL问题的方法,但是似乎没有任何帮助。帮助的一件事是编辑apache配置,在该配置中我为“ /”做了一个别名以重定向到/var/www/laravel/public文件夹。但这不是我的解决方案,因为那样我就无法访问phpmyadmin。

我的web.php文件中的路由:

Route::get('/', 'DashboardController@index');
Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
Route::get('/set-warehouse', 'DashboardController@setWarehouse');
Route::get('/pie-data', 'DashboardController@getDonutData');
Route::get('/mechanics-load', 'DashboardController@mechanicsWorkLoad');
Route::get('/monthly-load', 'DashboardController@monthlyLoad');
Route::get('/change-date-mechanics', 'DashboardController@changeMechanicsWorkLoad');

一个AJAX请求:

$.ajax({
    url: '/pie-data',
    method: 'GET',
    success: function (data) {
        if (data.type === 'success') {
            pieChart.Doughnut(data.data, pieOptions);
            $('canvas[id="pieChart"]').empty().after(data.legend);
        }
    },
});

000-default.conf文件:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerName server.xxxxxxx.com
    ServerAdmin somemail@gmail.com
    DocumentRoot /var/www/home/

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    Alias /erp "/var/www/laravel/public/"

    <Directory "/var/www/laravel/public/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

.htaccess文件是Laravel 5.8的标准文件,完全没有更改。

当用户在http://server.xxxxxxx.com/erp/dashboard中时,会进行4次或更多次AJAX调用,但不会进行http://server.xxxxxxx.com/erp/pie-chart(它将为插件返回JSON),但会进行http://server.xxxxxxx.com/pie-chart 。有什么方法可以解决此功能,而无需更改文件夹结构?预先感谢您的答复!

1 个答案:

答案 0 :(得分:0)

您的ajax请求正在尝试获取/ pie-data,更具体地说是(/ var / www / home / pie-data)看起来像/ erp / pie-data