gpt4 book ai didi

php - 在没有子域的子文件夹中安装多个 laravel 项目

转载 作者:IT王子 更新时间:2023-10-29 00:04:14 37 4
gpt4 key购买 nike

我已经尝试搜索此问题,但它与我的完全不同,所以我将其发布在这里。我正在尝试使用 nginx 创建一个网络服务器来在子文件夹中托管多个 laravel 项目。这是我的实验室服务器。所以我希望我的项目是这样的:

  • domain.com/project1
  • domain.com/project2
  • domain.com/project3

我正在为每个项目复制以下 nginx location block (我不知道这里发生了什么,我只是从互联网上复制并且有效):

location ^~ /project1/ {
alias /home/web/project1/public;
try_files $uri $uri/ @project1;

location ~ \.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/home/web/project1/public/index.php";
}

}

location @project1 {
rewrite /avm/(.*)$ /project1/index.php?/$1 last;
}

我的 laravel 应用程序中的 RESTful 路由是这样的:

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', ['middleware' => 'auth','uses' => 'HomeController@index'])->name('home');

// Authentication
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@authenticate');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Administração
Route::group(['prefix' => 'administracao', 'middleware' => 'auth'], function() {
Route::resource('filiais', 'FiliaisController');
Route::resource('precos', 'PrecosController');
Route::resource('funcionarios', 'FuncionariosController');
Route::resource('cargos', 'CargosController');
Route::resource('vendedores', 'VendedoresController');
});

// Comercial
Route::group(['prefix' => 'comercial', 'middleware' => 'auth'], function() {
Route::resource('clientes', 'ClientesController');
Route::resource('fichas', 'FichasController');
});

// Operacional
Route::group(['prefix' => 'operacional', 'middleware' => 'auth'], function() {
Route::resource('agenda', 'AgendaController');
Route::resource('os', 'OsController');
Route::resource('ambientes', 'AmbientesController');
Route::resource('processos', 'ProcessosController');
Route::get('relatorios', 'RelatoriosController@index');

Route::group(['prefix' => 'processo', 'middleware' => 'auth'], function() {
Route::get('create', 'ProcessoController@create');
Route::get('index', 'ProcessoController@index');

Route::post('{os}/parse', 'ProcessoController@parse');

Route::get('{os}', 'ProcessoController@principal');
Route::match(['get', 'post'], '{os}/detalhe', 'ProcessoController@detalhe');
Route::get('{os}/duplicidades', 'ProcessoController@duplicidades');
Route::get('{os}/restantes', 'ProcessoController@restantes');
Route::match(['get', 'post'], '{os}/auditoria', 'ProcessoController@auditoria');
Route::match(['get', 'post'], '{os}/operadores', 'ProcessoController@operadores');
Route::match(['get', 'post'], '{os}/divergencia', 'ProcessoController@divergencia');
Route::match(['get', 'post'], '{os}/finalizar', 'ProcessoController@finalizar');
Route::get('{os}/excluir/{setor}', 'ProcessoController@destroy');
});
});

虽然它在进入业务逻辑(保存到数据库等)时似乎可以工作(页面出现等),但它似乎有很多错误。例如,当我尝试在 url http://domain.com/project1/administracao/funcionarios 中创建新员工时,它给出了错误:SQLSTATE[42S22]: Column not found: 1054 未知列“/administracao/funcionarios”在中(它有点前置一些 url 路由)

当我设置像 project1.domain.com 这样的子域时,一切正常。但我不想为每个项目创建一个子域,我希望它在子文件夹 url 中工作。可能吗?

最佳答案

检查这个Nginx configuration相信对你有帮助

server {
server_name main-app.dev;
root /var/www/projects/main/public;


add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

index index.html index.htm index.php;
charset utf-8;
# sub_directory
location ^~ /sub-app {
alias /var/www/projects/sub/public;
try_files $uri $uri/ @sub;

location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 30000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/projects/sub/public/index.php;
}
access_log off;
error_log /var/www/projects/sub/storage/log/error.log error;
}

location @sub {
rewrite /sub/(.*)$ /sub/index.php?/$1 last;
} # end sub_directory

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

access_log off;
error_log /var/www/projects/main/storage/log/error.log error;

error_page 404 /index.php;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 30000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}

location ~ /\.(?!well-known).* {
deny all;
}}

关于php - 在没有子域的子文件夹中安装多个 laravel 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36404259/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com