简体   繁体   English

使用缓存配置在 laravel 中获取 nginx 环境变量

[英]Getting nginx environment variable in laravel with cached config

I use laravel framework on 2 websites, The application backend is one, but view paths is different for each site.我在 2 个网站上使用 laravel 框架,应用程序后端是一个,但每个站点的视图路径不同。 There is nginx variable "WEBSITE", which is available in PHP (phpinfo prints it).有 nginx 变量“WEBSITE”,在 PHP 中可用(phpinfo 打印它)。 When I run application locally, all is right.当我在本地运行应用程序时,一切正常。 But in production, I get exception what variable is not exists.但是在生产中,我得到异常什么变量不存在。

I discovered what during deploy running command php artisan config:cache, which cached all config in "bootstrap" directory.我在部署运行命令 php artisan config:cache 期间发现了什么,它将所有配置缓存在“bootstrap”目录中。 I don't may delete this command, because it ups performance of site.我不会删除这个命令,因为它会提高网站的性能。 This command caches all config including app/config/view.php file that descript changes in view paths, like this此命令缓存所有配置,包括描述视图路径更改的 app/config/view.php 文件,如下所示

'paths' => [
    resource_path('views/' . env('WEBSITE')),
],

but config already cached without variable and in this form is delivered to the production.但配置已经缓存,没有变量,并以这种形式交付给生产。 I don't understand how fix this problem, other that edit all views, base layouts for both sites.我不明白如何解决这个问题,除了编辑所有视图,两个站点的基本布局。 Does anyone know how to solve this problem in a simple way?有谁知道如何以简单的方式解决这个问题?

Just add a fallback by explicitly adding WEBSITE=somewebsiteurl in your production sites.env, then re-cache the config and try if it works.只需通过在您的生产站点.env 中显式添加 WEBSITE=somewebsiteurl 来添加后备,然后重新缓存配置并尝试它是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM