【问题标题】:Linux server, laravel problem with configurationLinux服务器,laravel配置问题
【发布时间】:2019-09-26 13:19:53
【问题描述】:

目前我正在搭建一个基于linux的新服务器,安装了apache2、MySQL、phpmyadmin等。

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

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

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

当用户通过http://server.xxxxxxx.com/ 访问服务器时,会被重定向到/home,那里有一个登录页面,基本上是web-app 的一张脸。

当用户转到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。有没有办法在不改变文件夹结构的情况下修复这个功能?提前感谢您的回复!

【问题讨论】:

标签: php ajax laravel server apache2


【解决方案1】:

您的 ajax 请求正在尝试获取 /pie-data,更具体地说是 (/var/www/home/pie-data) 当您想要 /erp/pie-data 时

【讨论】:

  • 是的,我想要 /erp/pie-data
猜你喜欢
  • 2010-10-19
  • 1970-01-01
  • 2016-09-12
  • 2011-02-21
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
  • 2019-03-13
相关资源
最近更新 更多