在没有子域的子文件夹中安装多个laravel项目【JAVA教程】

!
也想出现在这里? 联系我们
信息

在没有子域的子文件夹中安装多个laravel项目,第1张

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

我已经尝试过search这个问题,但是和我的都不一样,所以我在这里发布。 我试图创build一个使用Nginx在子文件夹中托pipe多个laravel项目的networking服务器。 这是我的实验室服务器。 所以我想要我的项目是这样的:

domain.com/project1

domain.com/project2

domain.com/project3

我正在为每个项目复制下面的Nginx location块(我不知道这里发生了什么,我只是从互联网上复制过来的):

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\’,\’AuthAuthController@getLogin\’); Route::post(\’auth/login\’,\’AuthAuthController@authenticate\’); Route::get(\’auth/logout\’,\’AuthAuthController@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\’,function() { Route::resource(\’clIEntes\’,\’ClIEntesController\’); Route::resource(\’fichas\’,\’FichasController\’); }); // Operacional Route::group([\’prefix\’ => \’operacional\’,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\’,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\’,\'{os}/auditoria\’,\’ProcessoController@auditoria\’); Route::match([\’get\’,\'{os}/operadores\’,\’ProcessoController@operadores\’); Route::match([\’get\’,\'{os}/divergencia\’,\’ProcessoController@divergencia\’); Route::match([\’get\’,\'{os}/finalizar\’,\’ProcessoController@finalizar\’); Route::get(\'{os}/excluir/{setor}\’,\’ProcessoController@destroy\’); }); });

htaccess mod-rewrite:从根目录链接到子目录 – 忽略子目录中的目录?

.htaccess无法parsing根文件夹中的HTML文件中的PHP

Apache 2的mod_rewrite和PHP。 修改htaccess的$ _SERVER 值?

在apache中检查移动设备并redirect到移动网站

在重写.htaccess中保留查询string

虽然它似乎工作(页面出现等),当它进入商业逻辑(保存到数据库等),它似乎有很多的错误。 例如,当我尝试在url中创build一个新员工http://domain.com/project1/administracao/funcionarios它给了我错误: sqlSTATE[42S22]: Column not found: 1054 UnkNown column \’/administracao/funcionarios\’ in (这是有点前置一些url路线)

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

.htaccess中$ 1与%1之间的区别

Codeigniter htaccess删除index.PHP和www

如何防止Apache / mod_rewrite将path视为具有相同名称的文件

.htaccess – 无声地重写/redirect到内部子文件夹

.htaccess与2个参数弄乱了CSS,Js,图像path

我认为这个问题可能在你的Nginx.conf文件中。 尝试这个:

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; } } location @project1 { rewrite /project1/(.*)$ /project1/index.PHP?/$1 last; }

另外,请确保/home/web/project1/位于Web根目录之外。

这就是说,真的不建议在子文件夹中运行Laravel。 在一个子域中更容易。

我从这个要点中得到了这个建议的基本思路。

不完全确定的解决方案,但我认为你应该尝试这些:

首先:在config/app.PHP文件中正确设置url 。

其次:审查public/web.config文件。 问题可能是这些配置覆盖你的Nginx。 考虑改变<action type=\”Rewrite\” url=\”project1/index.PHP\” />并且看看它返回的结果。

在最后一个例子中, var_dump模型并查找它来自哪里。

你有没有试过这种配置?

https://gist.github.com/tsolar/8d45ed05bcff8eb75404

我会尽快在明天进行测试,以便在我的环境中复制您的情况。

有一个简单的解决方案,“我希望它在子文件夹url中工作,这有可能吗?”。

脚步

1.使您的主域公用文件夹内的文件夹。 你需要创建3个文件夹

家用/网络/公共/ PROJECT1

家用/网络/公共/项目2

家用/网络/公共/项目3

2.在每个项目文件夹中,您需要粘贴laravel应用程序公用文件夹的内容

(从你的Laravel项目)project1 / public / {contents} – 复制到 – >(托管服务器)home / web / public / project1 / {contents}

上传公共根目录之外的其余laravel项目,并给该文件夹的写入权限。

现在打开(托管服务器)public / project1 / index.PHP更新这两个字段

需要__DIR __。\’/ .. / .. / PROJECTONE / bootstrap / autoload.PHP\’;

$ app = require_once __DIR __。/ .. / .. / PROJECTONE / bootstrap / app.PHP\’;

我已经使用一个简单的符号链接成功地在另一个站点的“子文件夹”中运行Laravel 5.4项目。

Nginx配置中没有时髦的特殊重写规则。 没有复制和粘贴项目的部分。 没有提及路线中的子文件夹。 只是一个普通的Laravel 5项目整齐地包含在服务器上的某个地方,并且它是来自主站点文档根目录的公共文件夹的符号链接。

/var/www/domain.com/public/project1 –> /var/www/project1/public

所有的路线只是工作!

在编写视图时,必须将asset()辅助函数中客户端资源的路径包装起来,以便HTML中的路径包含子文件夹,浏览器可以找到它们。

<!– Styles –> <link href=\”{{ asset(\’CSS/app.CSS\’) }}\” rel=\”stylesheet\”>

但是这样做并不会使你的代码不那么灵活,因为如果你在一个没有通过子文件夹访问的环境中运行这个站点,它就会工作,因为asset()和地址栏一起工作。

尝试这样的东西….我为我的服务器使用以下的.conf :

server { Listen 80; root /vagrant; index index.HTML index.htm index.PHP app.PHP app_dev.PHP; server_name 192.168.33.10.xip.io; access_log /var/log/Nginx/vagrant.com-access.log; error_log /var/log/Nginx/vagrant.com-error.log error; charset utf-8; location ~project(d*)/((.*).(?:CSS|cur|Js|jpg|jpeg|gif|htc|ico|png|HTML|xml))$ { rewrite project(d*)/((.*).(?:CSS|cur|Js|jpg|jpeg|gif|htc|ico|png|HTML|xml))$ /project$1/public/$2 break; } location /project1{ rewrite ^/project1/(.*)$ /project1/public/index.PHP?$1 last; } location /project2 { rewrite ^/project2/(.*)$ /project2/public/index.PHP?$1 last; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.PHP; location ~ .PHP$ { fastcgi_split_path_info ^(.+.PHP)(/.+)$; fastcgi_pass unix:/var/run/PHP5-fpm.sock; fastcgi_index index.PHP; include fastcgi_params; set $laravel_uri $request_uri; if ($laravel_uri ~ project(d*)(/?.*)$) { set $laravel_uri $2; } fastcgi_param REQUEST_URI $laravel_uri; fastcgi_param Lara_ENV local; # Environment variable for Laravel fastcgi_param httpS off; } location ~ /.ht { deny all; } }

最近我有完全相同的问题。 我想要

http://customerdemo.example.com/project1/

http://customerdemo.example.com/project2/

http://customerdemo.example.com/project3/

但我讨厌每次添加新项目时都要修改Nginx conf。

以下是我想到的:

# Capture $project from /$projectname/controller/action map $request_uri $project { ~^/(?<captured_project>[a-zA-Z0-9_-]+)/? $captured_project; default / ; } server { Listen 11.22.33.44:80; server_name customerdemo.example.com www.customerdemo.example.com; # Use $project/public as root root /sites/customerdemo.example.com/$project/public; # Use index.PHP as directory index index index.PHP; # Include the basic h5bp config set (see https://github.com/h5bp/server-configs-Nginx) include h5bp/basic.conf; # Process /projectname/the/rest/of/the/url location ~ ^/([^/]+)/(.*) { # Save the rest of the URL after project name as $request_url set $request_url /$2; # If the saved url refers to a file in public folder (a static file),serve it,# else redirect to index.PHP,passing along any ?var=val URL parameters try_files $request_url /index.PHP?$is_args$args; } # Process any URL containing .PHP (we arrive here through prevIoUs location block) # If you don\’t need to serve any other PHP files besIDes index.PHP,use location /index.PHP here # instead,to prevent possible execution of user uploaded PHP code location ~ [^/].PHP(/|$) { # define $fastcgi_script_name and $fastcgi_path_info fastcgi_split_path_info ^(.+?.PHP)(/.*)$; # Immediately return 404 when script file does not exist if (!-f $document_root$fastcgi_script_name) { return 404; } # Mitigate https://httpoxy.org/ vulnerabilitIEs fastcgi_param http_PROXY \”\”; # define PHP backend location (find yours by grepPing \”Listen =\” # from your PHP config folder,eg grep -r \”Listen =\” /etc/PHP/) fastcgi_pass unix:/run/PHP/PHP7.0-fpm.sock; # Set SCRIPT_filename to execute fastcgi_param SCRIPT_filename $document_root$fastcgi_script_name; # Include the default fastcgi parameters include fastcgi_params; # Overwrite REQUEST_URI (default is $request_uri) with $request_url we saved earlIEr fastcgi_param REQUEST_URI $request_url; } }

结果是我不需要在/sites/customerdemo.example.com/文件夹下做任何其他的git clone ,运行composer install和PHP artisan migrate来添加一个新的项目。

实际上,我自己开发了一个控制面板,在这里我可以点击“添加项目”,指定项目细节和一个新的bitbucket仓库,MysqL用户和数据库将被创建,customerdemo服务器将被部署访问这个bitbucket仓库和webhook被设置在这个新的回购,这将调用一个部署脚本customerdemo服务器每次有人提交掌握这个回购,这将触发git克隆或git拉和作曲家安装和数据库迁移。 这就是为什么我需要动态的Nginx配置。 总结

以上是内存溢出为你收集整理的在没有子域的子文件夹中安装多个laravel项目全部内容,希望文章能够帮你解决在没有子域的子文件夹中安装多个laravel项目所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

© 版权声明
THE END
喜欢就支持一下吧
点赞115 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容