【发布时间】: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。有没有办法在不改变文件夹结构的情况下修复这个功能?提前感谢您的回复!
【问题讨论】:
-
使用 NGINX、MySQL 和 PHP 设置 Linux 服务器的完整说明:github.com/akshaykhale1992/nginx-php-mysql-setup
-
这对我没有任何帮助。我已经安装并配置了一切。
标签: php ajax laravel server apache2