以上就是给各位分享ApacheSetEnv无法与mod_wsgi一起正常工作,同时本文还将给你拓展Apache+mod_wsgivsnginx+gunicorn、Apache+mod_wsgi部署we
以上就是给各位分享Apache SetEnv无法与mod_wsgi一起正常工作,同时本文还将给你拓展Apache + mod_wsgi vs nginx + gunicorn、Apache + mod_wsgi 部署 webpy 应用、Apache 2.4与mod_wsgi:403 Forbidden,没有权限访问此服务器上的/ calbase、Apache Django Mod_Wsgi – 自动重载等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- Apache SetEnv无法与mod_wsgi一起正常工作
- Apache + mod_wsgi vs nginx + gunicorn
- Apache + mod_wsgi 部署 webpy 应用
- Apache 2.4与mod_wsgi:403 Forbidden,没有权限访问此服务器上的/ calbase
- Apache Django Mod_Wsgi – 自动重载
Apache SetEnv无法与mod_wsgi一起正常工作
在我编写的flask应用程序中,我使用了一个外部库,该库可以使用环境变量进行配置。注意:我自己编写了这个外部库。因此,如有必要,我 可以
进行更改。从命令行运行时,运行带有以下内容的烧瓶服务器:
# env = python virtual environmentENV_VAR=foo ./env/bin/python myapp/webui.py
一切都如预期。但将它部署到Apache后,用SetEnv
它 不
工作了。事实上,打印出os.environ
到stderr
(所以它在Apache日志中显示出来显示,该wsgi
过程似乎是在一个非常不同的环境(一个,os.environ[''PWD'']
好像是
这样 了。其实,它指向我的发展的文件夹。
为了帮助识别问题,以下是作为独立的hello-world应用程序的应用程序的相关部分。错误输出和观察都在帖子的最后。
应用文件夹的布局:
Python应用程式:
.├── myapp.ini├── setup.py└── testenv ├── __init__.py ├── model │ └── __init__.py └── webui.py
Apache文件夹(/var/www/michel/testenv
):
.├── env│ ├── [...]├── logs│ ├── access.log│ └── error.log└── wsgi└── app.wsgi
myapp.ini
[app]somevar=somevalue
setup.py
from setuptools import setup, find_packagessetup( name="testenv", version=''1.0dev1'', description="A test app", long_description="Hello World!", author="Some Author", author_email="author@example.com", license="BSD", include_package_data=True, install_requires = [ ''flask'', ], packages=find_packages(exclude=["tests.*", "tests"]), zip_safe=False,)
testenv / init .py
# empty
testenv / model / init .py
from os.path import expanduser, join, existsfrom os import getcwd, getenv, pathsepimport loggingimport sys__version__ = ''1.0dev1''LOG = logging.getLogger(__name__)def find_config(): """ Searches for an appropriate config file. If found, return the filename, and the parsed search path """ path = [getcwd(), expanduser(''~/.mycompany/myapp''), ''/etc/mycompany/myapp''] env_path = getenv("MYAPP_PATH") config_filename = getenv("MYAPP_CONFIG", "myapp.ini") if env_path: path = env_path.split(pathsep) detected_conf = None for dir in path: conf_name = join(dir, config_filename) if exists(conf_name): detected_conf = conf_name break return detected_conf, pathdef load_config(): """ Load the config file. Raises an OSError if no file was found. """ from ConfigParser import SafeConfigParser conf, path = find_config() if not conf: raise OSError("No config file found! Search path was %r" % path) parser = SafeConfigParser() parser.read(conf) LOG.info("Loaded settings from %r" % conf) return parsertry: CONF = load_config()except OSError, ex: # Give a helpful message instead of a scary stack-trace print >>sys.stderr, str(ex) sys.exit(1)
testenv / webui.py
from testenv.model import CONFfrom flask import Flaskapp = Flask(__name__)@app.route(''/'')def index(): return "Hello World %s!" % CONF.get(''app'', ''somevar'')if __name__ == ''__main__'': app.debue = True app.run()
Apache配置
<VirtualHost *:80> ServerName testenv-test.my.fq.dn ServerAlias testenv-test WSGIDaemonProcess testenv user=michel threads=5 WSGIScriptAlias / /var/www/michel/testenv/wsgi/app.wsgi SetEnv MYAPP_PATH /var/www/michel/testenv/config <Directory /var/www/michel/testenv/wsgi> WSGIProcessGroup testenv WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> ErrorLog /var/www/michel/testenv/logs/error.log LogLevel warn CustomLog /var/www/michel/testenv/logs/access.log combined</VirtualHost>
app.wsgi
activate_this = ''/var/www/michel/testenv/env/bin/activate_this.py''execfile(activate_this, dict(__file__=activate_this))from os import getcwdimport logging, sysfrom testenv.webui import app as application# You may want to change this if you are using another logging setuplogging.basicConfig(stream=sys.stderr, level=logging.DEBUG)LOG = logging.getLogger(__name__)LOG.debug(''Current path: {0}''.format(getcwd()))# Application configapplication.debug = False# vim: set ft=python :
错误与观察
这是apache错误日志的输出。
[Thu Jan 26 10:48:15 2012] [error] No config file found! Search path was [''/home/users/michel'', ''/home/users/michel/.mycompany/myapp'', ''/etc/mycompany/myapp''][Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] mod_wsgi (pid=17946): Target WSGI script ''/var/www/michel/testenv/wsgi/app.wsgi'' cannot be loaded as Python module.[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] mod_wsgi (pid=17946): SystemExit exception raised by WSGI script ''/var/www/michel/testenv/wsgi/app.wsgi'' ignored.[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] Traceback (most recent call last):[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] File "/var/www/michel/testenv/wsgi/app.wsgi", line 10, in <module>[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] from testenv.webui import app as application[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] File "/var/www/michel/testenv/env/lib/python2.6/site-packages/testenv-1.0dev1-py2.6.egg/testenv/webui.py", line 1, in <module>[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] from testenv.model import CONF[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] File "/var/www/michel/testenv/env/lib/python2.6/site-packages/testenv-1.0dev1-py2.6.egg/testenv/model/__init__.py", line 51, in <module>[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] sys.exit(1)[Thu Jan 26 10:48:15 2012] [error] [client 10.115.192.101] SystemExit: 1
我的第一个观察结果是环境变量MYAPP_PATH
未出现os.environ
(在此输出中不可见,但我对其进行了测试,并且不存在!)。这样,配置“解析程序”将退回到默认路径。
我的第二个观察结果是配置文件列表的搜索路径,其/home/users/michel
返回值为os.getcwd()
。我实际上在期待里面的东西/var/www/michel/testenv
。
我的直觉告诉我,我做配置解析的方式不正确。主要是因为代码是在导入时执行的。这使我想到一个想法,即可能在正确设置WSGI环境 之前
执行配置解析代码。我在那儿吗?
简短讨论/切线问题
在这种情况下, 您
将如何进行配置解析?鉴于“模型”子文件夹实际上是一个外部模块,该模块也应在非wsgi应用程序中运行,并应提供一种配置数据库连接的方法。
就个人而言,我喜欢搜索配置文件的方式,但仍然能够覆盖它。只是,代码在导入时执行的事实使我的蜘蛛感像疯了似的。其背后的原理是:使用此模块的其他开发人员完全隐藏了配置处理(抽象屏障),并且“正常工作”。他们只需要导入模块(当然具有现有的配置文件),就可以直接跳入而无需了解任何数据库详细信息。这也为他们提供了一种使用不同数据库(开发/测试/部署)并在它们之间轻松切换的简便方法。
现在,在mod_wsgi内部,它不再:(
更新:
刚才,为了测试我的上述想法,我将更改为webui.py
以下内容:
import osfrom flask import Flask, jsonifyapp = Flask(__name__)@app.route(''/'')def index(): return jsonify(os.environ)if __name__ == ''__main__'': app.debue = True app.run()
该网页上的输出如下:
{ LANG: "C", APACHE_RUN_USER: "www-data", APACHE_PID_FILE: "/var/run/apache2.pid", PWD: "/home/users/michel/tmp/testenv", APACHE_RUN_GROUP: "www-data", PATH: "/usr/local/bin:/usr/bin:/bin", HOME: "/home/users/michel/"}
这显示了与其他调试方法所看到的环境相同的环境。所以我最初的想法是错误的。但是现在我意识到了一个陌生的东西。os.environment[''PWD'']
设置为我的开发文件所在的文件夹。这不是在
所有
的应用程序运行的位置。陌生人os.getcwd()
回来了/home/users/michel
吗?这与我在中看到的不一致os.environ
。应该不一样os.environ[''PWD'']
吗?
但是,最重要的问题仍然存在:为什么在中找不到apache SetEnv
(MYAPP_PATH
在这种情况下)设置的值os.environ
?
答案1
小编典典注意,WSGI环境是在每次请求时通过应用environ
程序对象的参数传递给应用程序的。该环境与保存在其中的过程环境完全无关os.environ
。该SetEnv
指令无效,os.environ
并且无法通过Apache配置指令来影响流程环境中的内容。
因此,您必须要做其他事情,getenviron
或者要从apache中os.environ[''PWD'']
获取MY_PATH
。
Flask将wsgi周围环境添加到请求中,而不是app.environ
由下层完成werkzeug
。因此,例如,在对应用程序的每个请求中,apache都会添加MYAPP_CONF
密钥,并且您可以在任何可以访问请求的地方访问它request.environ.get(''MYAPP_CONFIG'')
。
Apache + mod_wsgi vs nginx + gunicorn
我想部署一个Django站点(这是在github上的开源edx代码)。
我面临着使用之间的select
Apache与mod_wsgi
Nginx与gunicorn
我已经用mod_wsgi使用了Apache,它足够酷,但我没有第二个选项的经验。
哪一个在速度方面是更好的select,在某种程度上也就是易用性?
结束perl脚本而不等待系统调用返回
运行Silverlight与Apache服务器(在Linux下)
在CentOS 6.4上的apache 2.0中创build虚拟主机中的子域
Codeigniter URL重写删除index.PHP
XAMPP / WAMP /不pipe它是什么:Apache运行速度超慢
注意:我需要运行两个不同的django站点,比如端口80和81,并从两个不同的子域访问它们。
用连字符replace空格%20和+
PHP – 每个虚拟主机不同的open_basedir
Apache无法启动 – ServerRoot必须是有效的目录,无法find指定的模块
RuntimeError:populate()在Django中不可重入
Apache意外关机
Nginx是一个非常简单易用的解决方案,它可以让我们运行任何wsgi应用程序并轻松扩展。 Nginx在处理请求方面更好,因为它不会像Apache那样为每个请求产生一个新的进程。
我已经写了一个关于如何与Nginx一起部署django的相关问题的答案:
使用Gunicorn和Nginx部署Django项目
我对Nginx和gunicorn有很好的经验。 当我最终设置好所有的设置并运行后,它们继续工作。
对于Nginx和gunicorn他们是:
* Nginx configuration files (/etc/Nginx/sites-enabled/ and /etc/Nginx/Nginx.conf) * gunicorn configuration files (/etc/init/gunicorn.conf and /etc/gunicorn.d/)
我已经看到了apache + mod_wsgi的教程,它似乎更容易设置。
总结
以上是小编为你收集整理的Apache + mod_wsgi vs nginx + gunicorn全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
Apache + mod_wsgi 部署 webpy 应用
Apache + mod_wsgi 部署 webpy 应用
- 您可以使用您自己的项目名称替换’appname’。
- 您可以使用您自己的文件名称替换’code.py’。
- /var/www/webpy-app 为包含您的 code.py 的文件夹目录路径。
- /var/www/webpy-app/code.py 是您的 python 文件的完整路径。
- 下载和安装 mod_wsgi 从它的网站:
- 在 httpd.conf 中配置 Apache 加载 mod_wsgi 模块和您的项目:
- 演示文件 ‘code.py’:
在您的浏览器地址栏中输入’ http://your_server_name/appname’ 来验证它是否可用。
Apache 2.4与mod_wsgi:403 Forbidden,没有权限访问此服务器上的/ calbase
所以我试图在Windows服务器上部署我的django项目,使用mod_wsgi和pythong 3.4的apache 2.4。 在configurationhttpd.conf之前,只要尝试启动安装了mod-wsgi的apache,它就能正常工作,并向我显示“it works”页面。 然后我在httpd.conf中做了以下configuration:
# Change Python path used by the server. WsgiPythonPath “/EquipmentCalibration” # Make calls to http://localhost/ refer to the Python/Wsgi-script located at the specified location. WsgiScriptAlias / /EquipmentCalibration/equipcal/wsgi.py # Make calls to http://localhost/static refer to the specified folder. Alias /static/ /EquipmentCalibration/static Alias /media/ /EquipmentCalibration/media <Directory /EquipmentCalibration/static> Require all granted </Directory> <Directory /EquipmentCalibration/media> Require all granted </Directory> <Directory /EquipmentCalibration/equipcale> <Files wsgi.py> Require all granted </Files> </Directory>
然后尝试去本地主机:8080(我把端口从80改为8080),我得到这个错误说:
被禁止
您无权访问/在此服务器上。
友好的URL空格连字符和大写字母小写
在htaccess文件中使用RewriteMap
有条件地设置Apache头
.htaccess指令*不*redirect某些URL
Windows上的Apache / PHP使用正则expression式崩溃
下面是相关的error.log。
[Thu Sep 29 15:05:25.171920 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00456: Apache Lounge VC10 Server built: Jul 9 2016 11:59:00 [Thu Sep 29 15:05:25.171920 2016] [core:notice] [pid 7756:tid 528] AH00094: Command line: 'C:\Apache24\bin\httpd.exe -d C:/Apache24' [Thu Sep 29 15:05:25.171920 2016] [mpm_winnt:notice] [pid 7756:tid 528] AH00418: Parent: Created child process 7524 [Thu Sep 29 15:05:25.500078 2016] [wsgi:warn] [pid 7524:tid 456] mod_wsgi: Compiled for Python/3.4.2. [Thu Sep 29 15:05:25.500078 2016] [wsgi:warn] [pid 7524:tid 456] mod_wsgi: Runtime using Python/3.4.3. [Thu Sep 29 15:05:26.171978 2016] [mpm_winnt:notice] [pid 7524:tid 456] AH00354: Child: Starting 64 worker threads. [Thu Sep 29 15:05:27.174429 2016] [mpm_winnt:notice] [pid 7636:tid 456] AH00364: Child: All worker threads have exited. [Thu Sep 29 15:05:29.923754 2016] [authz_core:error] [pid 7524:tid 1108] [client ::1:55483] AH01630: client denied by server configuration: C:/EquipmentCalibration/equipcal/wsgi.py
有人可以帮忙吗? TIA。
NetBeans 7.0.1:访问Tomcat服务器尚未获得授权
Apache负载均衡tomcat websocket
如何在CGI模式下运行时重写PHPconfiguration
redirect所有的url,只需更改域名
我怎么能允许通过HTTP匿名推送到一个Git仓库?
这部分:
<Directory /EquipmentCalibration/equipcale> <Files wsgi.py> Require all granted </Files> </Directory>
有一个与WsgiScriptAlias指令中使用的内容匹配的目录名称。 一个使用equipcal和另一个equipcale 。 他们需要在该段名称匹配。
Apache Django Mod_Wsgi – 自动重载
我试图自动重新加载我的本地Windows机器上使用Apache + mod_wsgi的Django应用程序。
我想知道我在哪里添加下面的文章中引用的代码:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
def _restart(path): _queue.put(True) prefix = ''monitor (pid=%d):'' % os.getpid() print >> sys.stderr,''%s Change detected to ''%s''.'' % (prefix,path) print >> sys.stderr,''%s Triggering Apache restart.'' % prefix import ctypes ctypes.windll.libhttpd.ap_signal_parent(1)
如何在Apacheasynchronous客户端中configuration允许的挂起请求数量
无法导入/没有名为与Django错误的模块
node.js与Apache PHP一起运行?
如何htaccessredirect这个长的url?
multipartentity不能被parsing为一个types
Windows生产服务器上的Drupal 7和wordpress 3.8?
404未find在此服务器上未find请求的URL
没有findAndroid库
www将301redirect到使用httpd.conf的非www的语法
我试图在Windows 7 x64上构buildApache Hadoop 2.5.0,但是我仍然遇到未知的错误
读:
http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html
它告诉你在使用Django的时候文件的放置位置。 您只需要在与Windows相关的源代码重新加载文档部分中更改每个人都指出的代码。 另请阅读:
http://blog.dscpl.com.au/2009/02/source-code-reloading-with-modwsgi-on.html
这解释了与Windows相关的第一个变体。
您替换同一篇文章中上面的代码块中提到的重新启动函数。
您可以在您在页面上找到的以下代码块中替换重新启动功能:
Monitoring For Code Changes The use of signals to restart a daemon process Could also be employed in a mechanism which automatically detects changes to any Python modules or dependent files. This Could be achieved by creating a thread at startup which periodically looks to see if file timestamps have changed and trigger a restart if they have. Example code for such an automatic restart mechanism which is compatible with how mod_wsgi works is shown below. import os import sys import time import signal import threading import atexit import Queue _interval = 1.0 _times = {} _files = [] _running = False _queue = Queue.Queue() _lock = threading.Lock() def _restart(path): _queue.put(True) prefix = ''monitor (pid=%d):'' % os.getpid() print >> sys.stderr,''%s Triggering process restart.'' % prefix os.kill(os.getpid(),signal.SIGINT)
我在我的服务器上使用这个代码
touch site.wsgi
它的工作。 在浏览器重新加载页面后,我得到页面的变化。 可能是丑陋 – 但简单,没有必要重新启动Apache。
我使用Bitnami DjangoStack http://bitnami.org/stack/djangostack和安装在D: BitNami DjangoStack和C: Documents and Settings tsurahman BitNami DjangoStack projects myproject上的Windows XP作为项目目录(默认安装)
如在http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Apache_Processes中 ,我添加
MaxRequestsPerChild 1
在文件D: BitNami DjangoStack apps django conf django.conf中查看Graham Dumpleton的评论
然后我使用http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes中的内容在我的项目目录中创建了一个文件monitor.py ,并用http://code.google.com替换_restart方法/ p / modwsgi / wiki / ReloadingSourceCode#Restarting_Windows_Apache ,这里是脚本的一部分
.... _running = False _queue = Queue.Queue() _lock = threading.Lock() def _restart(path): _queue.put(True) prefix = ''monitor (pid=%d):'' % os.getpid() print >> sys.stderr,''%s Triggering Apache restart.'' % prefix import ctypes ctypes.windll.libhttpd.ap_signal_parent(1) def _modified(path): try: ....
并在文件D: BitNami DjangoStack apps django scripts django.wsgi中 ,
.... import django.core.handlers.wsgi import monitor monitor.start(interval=1.0) monitor.track(os.path.join(os.path.dirname(__file__),''site.cf'')) application = django.core.handlers.wsgi.WsgiHandler()
然后重新启动Apache服务器
总结
以上是小编为你收集整理的Apache Django Mod_Wsgi – 自动重载全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
今天关于Apache SetEnv无法与mod_wsgi一起正常工作的介绍到此结束,谢谢您的阅读,有关Apache + mod_wsgi vs nginx + gunicorn、Apache + mod_wsgi 部署 webpy 应用、Apache 2.4与mod_wsgi:403 Forbidden,没有权限访问此服务器上的/ calbase、Apache Django Mod_Wsgi – 自动重载等更多相关知识的信息可以在本站进行查询。
本文标签: