问题描述
,我不能传递给Apache,一个变量定义在/ etc / profile文件。
I'm looking for a solution, I can't pass to apache a variable define in /etc/profile.
下面是什么,我想设置:
Here is what I am trying to set:
我必须通过WGSI接口,我通过Apache /乘客(modrails)部署Django应用程序。
I have a django application that I deploy through Apache/Passenger (modrails) through the WGSI interface.
在我的settings.py我使用这条巨蟒的命令:
环境= os.getenv('ENV','PROD')
因此,如果环境变量没有定义它在默认情况下进入到生产设置。
In my settings.py I am using this python command : ENVIRONMENT = os.getenv('ENV', 'PROD')so if the ENVIRONMENT variable is not define it goes to the production settings by default.
这是帮我管理我连接的DB并激活调试工具。
That is helping me to manage which DB I connect to and activate debugging tools.
这是在生产中工作,因为它是默认值时,当我开发服务器,我不能从/ etc / profile文件获取环境变量上的。
It is working in production because it is the default values, it's when I am on the DEV server that I can't get the environment variable from /etc/profile.
这是一个Ubuntu 10.04服务器上
It is on an Ubuntu 10.04 Server
因此,这里是一些测试我所做的:
So here is some test I did:
1)放入/ etc / profile文件 - >
ENV ='DEV'
出口ENV
1) put into /etc/profile -> ENV='DEV' export ENV
2)根据/etc/profile.d/environment.sh - >
#!/ bin / sh的
ENV ='DEV'
出口ENV
2) under /etc/profile.d/environment.sh -> #!/bin/sh ENV='DEV' export ENV
3)在我的虚拟主机配置文件 - >
PassEnv ENV
3) in my virtual host config file -> PassEnv ENV
4)仍然在我的虚拟主机配置文件 - >
SETENV ENV DEV
4) still in my virtual host config file -> SetEnv ENV DEV
5)的乘客需要passenger_wgsi.py,如果我在这个文件中强制注册您的应用程序
病毒粒子['ENV'] ='DEV'这走了一个工作,但我不能做到这一点。
5) passenger require a passenger_wgsi.py to register your application if I force in this file viron['ENV'] = 'DEV' this gone a work but I am not able to do this
ENVIRONMENT = os.getenv('ENV', 'PROD')
os.environ['ENV'] = ENVIRONMENT
任何想法,为什么或如何才能解决这个问题?
谢谢!
@Josh
感谢您的答复。但我仍然有一些问题。
Thanks for the reply. But I still have some questions.
通过客运,唯一的东西,我不得不在虚拟主机文件中设置
是我的Python / Django应用程序内的公共文件夹的位置。
所以,我的虚拟主机文件看起来是这样的。
With Passenger, the only things I had to set in the virtual host filewas the location of the public folder inside my python/django app.So my virtual host file would look like this.
DocumentRoot path_to_my_public_folder # /home/user/workspace/myapp/public
然后MyApp文件夹里面就有passenger_wsgi.py
Then inside the myapp folder there is the passenger_wsgi.py
说:
import sys, os
sys.path.append(os.getcwd())
os.environ['DJANGO_SETTINGS_MODULE'] = "myapp.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
和这些设置,这是它后,该应用程序正在运行。
那么,我也许缺少你指示,你是说,我们必须指定时
我们使用的WSGI文件。我虽然它会直接定位passenger_wsgi.py,默认情况下它似乎加载
此刻做的事情。
and after these settings that was it, the application was running.So where I'm maybe missing your indication is when you are saying that we have to specify which wsgi file we used. I though it would directly locate passenger_wsgi.py and load it by default what it seemsto be doing at the moment.
你应该知道事情的另一个是,我们的项目是居住在一个SVN仓库,
我想设置该文件对于很多用户,所以我们不会有不同的设置。
Another things you should know is that our project is residing in an SVN repository and I want to setup this file for many users so we don't have different settings.
但我会测试tomorow是具有与普通信息的一个基地WSGI文件的想法
和底座上的计算机的主机名,我会像从或dev_wsgi.py导入prod_wsgi.py其他设置
But what I will test tomorow is the idea of having one base wsgi file with the common informationand base on the hostname of the computer I will import the others settings from like dev_wsgi.py or prod_wsgi.py
我应该能够使用Python和底座上的名称获取这个名字我将我需要使用的变量。
I should be able to retrieve this name with python and base on the name I will set the variables I need to use.
感谢您的想法,这是非常AP preciate。
Thank you for the idea, it is well appreciate.
推荐答案
我要去,因为我不知道如何解决您的具体问题提出替代解决方案。
I'm going to suggest an alternative solution since I have no idea how to fix your specific problem.
创建多个WSGI文件。 production.wsgi
, dev1.wsgi
, dev2.wsgi
, test.wsgi
等。每个Web服务器必须与 /path/to/.wsgi
反正进行配置。有一个WSGI文件code的仅有极少量无论如何,因此复制此也不是很贵。此外,你可以有一个 _base.wsgi
来提供所有的共同价值观,并要求衍生wsgis调用应用程序= wsgi.WSGIHandler()
。
Create multiple WSGI files. production.wsgi
, dev1.wsgi
, dev2.wsgi
, test.wsgi
etc. Each webserver has to be configured with the /path/to/.wsgi
anyway. There is only a minimal amount of code in a wsgi file anyway, so replicating this isn't very expensive. Also, you could have a _base.wsgi
to supply all the common values, and require the derived wsgis to call application = wsgi.WSGIHandler()
.
在我们的项目中每个开发者都有自己的设置文件和文件WSGI使更改设置而没有能够打破生产与流氓值。
Each developer on our project has their own setting files and wsgi files to enable tampering with settings without ever being able to break production with a rogue value.
这篇关于Django的 - 无法通过环境变量到Apache /乘客在WSGI接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!