设置Apache和Python WSGI以使用VirtualEnv(Setting up Apache and Python WSGI to use VirtualEnv)
我无法让Apache / WSGI使用我的VirtualEnv。 我已将以下两行(服务器上的路径指向目标virtualenv中的站点包的实际位置)添加到我的WSGI文件中:
import site site.addsitedir('/sites/mysite/virtpy/lib/python2.6/site-packages')
(从http://www.foxhop.net/django-virtualenv-apache-mod_wsgi )。 但是,当我尝试在浏览器中加载url时,我得到一个500.检查apache日志:
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] app = import_module(appname) [Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module [Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] __import__(name) [Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] TemplateSyntaxError: Caught ImportError while rendering: No module named tagging [Sun Jul 17 11:07:11 2011] [debug] mod_deflate.c(615): [client 94.170.105.142] Zlib: Compressed 629 to 387 : URL /
所以我猜想VirtualEnv没有被加载。 任何人都知道如何告诉Apache / WSGI使用正确的virtualenv?
UPDATE
我按照Ken的建议更新了django.wsgi,但现在我在apache日志中发现了以下错误
[Sun Jul 17 16:46:36 2011] [info] [client 94.170.105.142] mod_wsgi (pid=11260, process='', application='igniteflow-django.com:8090|'): Loading WSGI script '/sites/igniteflow/apache/django.wsgi'. [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Target WSGI script '/sites/igniteflow/apache/django.wsgi' cannot be loaded as Python module. [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Exception occurred processing WSGI script '/sites/igniteflow/apache/django.wsgi'. [Sun Jul 17 16:46:36 2011] [error] [client 94.170.106.142] Traceback (most recent call last): [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] File "/sites/igniteflow/apache/django.wsgi", line 5, in <module> [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] execfile(activate_this, dict(__file__=activate_this)) [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] IOError: [Errno 13] Permission denied: '/root/.virtualenvs/igniteflow/bin/activate_this.py'
我认为这是因为virtualenv是在根和Apache没有权限? 我把这个文件夹变成root:www-data,但它没有解决问题。 有什么建议么?
I'm having trouble getting Apache/WSGI to use my VirtualEnv. I have added the following two lines (path on server is pointing to the actual location of site-packages in the target virtualenv) to my WSGI file:
import site site.addsitedir('/sites/mysite/virtpy/lib/python2.6/site-packages')
(from http://www.foxhop.net/django-virtualenv-apache-mod_wsgi). However, when I try to load the url in the browser I get a 500. Checking the apache logs:
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] app = import_module(appname) [Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module [Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] __import__(name) [Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] TemplateSyntaxError: Caught ImportError while rendering: No module named tagging [Sun Jul 17 11:07:11 2011] [debug] mod_deflate.c(615): [client 94.170.105.142] Zlib: Compressed 629 to 387 : URL /
So I guess that the VirtualEnv isn't being loaded. Anyone know how to tell Apache / WSGI the correct virtualenv to use?
UPDATE
I have updated django.wsgi following Ken's advice, but now I am getting the following error in the apache log
[Sun Jul 17 16:46:36 2011] [info] [client 94.170.105.142] mod_wsgi (pid=11260, process='', application='igniteflow-django.com:8090|'): Loading WSGI script '/sites/igniteflow/apache/django.wsgi'. [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Target WSGI script '/sites/igniteflow/apache/django.wsgi' cannot be loaded as Python module. [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Exception occurred processing WSGI script '/sites/igniteflow/apache/django.wsgi'. [Sun Jul 17 16:46:36 2011] [error] [client 94.170.106.142] Traceback (most recent call last): [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] File "/sites/igniteflow/apache/django.wsgi", line 5, in <module> [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] execfile(activate_this, dict(__file__=activate_this)) [Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] IOError: [Errno 13] Permission denied: '/root/.virtualenvs/igniteflow/bin/activate_this.py'
I assume this is because the virtualenv is in root and apache doesn't have permissions? I chowned the folder to root:www-data but it hasn't fixed the problem. Any suggestions?
原文:https://stackoverflow.com/questions/6723494
最满意答案
URL转发的工作方式取决于提供者。 如果您的提供商在发送重定向时未包含路径,您应该找到一个例如 - zoneedit的人 。
How URL forwarding works depends on the provider. If your provider doesn't include the path when sending a redirect, you should find one who does - zoneedit, for instance.
相关问答
更多-
无法使用Hostgator从Heroku重定向到裸域(Unable to redirect to a naked domain from Heroku using Hostgator)[2023-04-03]
在与客户服务部门共度数小时后,我找到了我需要的东西。 Hostgator不提供此功能来映射到没有A记录的裸域。 谢天谢地,我找到了http://wwwizer.com/naked-domain-redirect 这是一项免费服务,可以解决这个问题...... After spending hours with the customer service I found what I need. Hostgator does not provide this feature to map to naked do ... -
看到这篇文章 。 适用于我,虽然看起来像一个黑客。 我认为值得将问题发布到谷歌,因为servlet规范要求在尝试找到适当的欢迎文件时添加尾随斜线。 See this post. Works for me, though looks like a hack. I think it worth posting issue to google, as thee servlet specification requires adding trailing slashes when attempting to fin ...
-
Google App Engine裸域重定向 - 处理GET请求(Google App Engine naked domain redirect - handle the GET request)[2022-06-03]
URL转发的工作方式取决于提供者。 如果您的提供商在发送重定向时未包含路径,您应该找到一个例如 - zoneedit的人 。 How URL forwarding works depends on the provider. If your provider doesn't include the path when sending a redirect, you should find one who does - zoneedit, for instance. -
身份发现规范明确要求消费者遵循所有重定向。 从第7.2节。 OpenID 2.0规范的 规范化 : URL标识符必须在检索其内容时通过以下重定向进一步标准化,并最终将[RFC3986] [...]的第6节中的规则应用于最终目标URL。 该最终URL必须由依赖方记录为声明的标识符,并在请求认证(请求认证)时使用。 您的设置预计会正常工作。 The specification on identity discovery explicitly calls for the consumer to follow al ...
-
如果您使用Go Daddy域转发,则需要使用停放的名称服务器,并且需要确保使用IP 64.202.189.170。 如果您没有将此IP用于A记录,则转发将不起作用。 If you are using Go Daddy domain forwarding you need to be on the parked nameservers and you need to ensure that you are using the IP 64.202.189.170. If you are not using th ...
-
与Openshift的裸域(Naked domain with Openshift)[2022-12-11]
根据我的记忆,DNS A-Records需要静态IP地址,而Openshift online目前无法为应用程序分配静态IP。 From what I remember DNS A-Records require a static IP address and Openshift online currently does not have the ability to assign a static IP to an app. -
AFAIK您无法对静态资产进行重定向,因为GAE根据.yaml文件规则直接为其提供服务,甚至无需点击您的应用程序代码。 您可以添加一个模块(例如, 将其称为redirect-module )到您的应用程序,使用调度程序文件将所有旧域URL路由到它,并使用此模块中的动态处理程序将URL重定向到新的域等效项,沿着这些行在您引用的问题的答案中建议。 新域请求将继续未经修改地工作,作为静态资产或应用程序的现有模块提供。 dispatch.yaml文件如下所示: application: your-app-name ...
-
Google App Engine - Python中的裸域路径重定向(Google App Engine - Naked Domain Path Redirect in Python)[2023-04-13]
我在这种情况下做的是在你的裸域建立一个小站点,它只包含一个.htaccess文件,它将路径重定向到www。*: Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^colorurl.com [NC] RewriteRule ^(.*)$ http://www.colorurl.com/$1 [L,R=301] What I'd do in this scenario is set up a small site at ... -
步骤5c中建议的DNS操作( 此处的文档 )是不够的,您还需要将裸域添加到GAE配置(除了www之外) - 步骤5d。 5. Continue to the next step the Add new custom domain form, selecting the custom domain you want to point to your App Engine app: a. Refresh the console domain page so it will list the domai ...
-
我今天刚刚发现(截至2014-04-11),Google Developers Console提供了一个新的自定义域名设置页面: 转到https://console.developers.google.com/project 点击你的项目 在左侧单击“App Engine” 点击“设置” 在那里,您可以选择直接添加裸域。 I just discovered today (as of 2014-04-11) a new custom domain settings page is available from ...