简体   繁体   English

Python Web服务器-mod_wsgi

[英]Python Web Server - mod_wsgi

I have been looking at setting up a web server to use Python and I have installed Apache 2.2.22 on Debian 7 Wheezy with mod_wsgi. 我一直在寻找设置Web服务器以使用Python的方法,并且已经在Debian 7 Wheezy上使用mod_wsgi安装了Apache 2.2.22。 I have gotten the initial page up and going and the Apache will display the contents of the wsgi file that I have in my directory. 我已经建立了初始页面,Apache将显示目录中的wsgi文件的内容。

However, I have been researching on how to deploy a Python application and I have to admin, I find some of it a little confusing. 但是,我一直在研究如何部署Python应用程序,并且必须进行管理,我发现其中有些令人困惑。 I am coming from a background in PHP where it is literally install what you need and you are up and running and PHP is processing the way it should be. 我来自PHP的背景,它实际上是在安装您所需的东西,并且您已启动并运行,PHP正在按照应有的方式进行处理。

Is this the same with Python? Python也一样吗? I can't seem to get anything to process outside of the wsgi file that I have setup. 我似乎无法在已设置的wsgi文件之外进行任何处理。 I can't import anything from other files without the server throwing a "500" error. 没有服务器抛出“ 500”错误,我无法从其他文件导入任何内容。 I have looked on Google and Bing to try to find an answer to this, but I can't seem to find anything, or don't know that what I have been looking at is the answer. 我曾在Google和Bing上寻找过答案,但似乎什么也找不到,或者不知道我一直在寻找答案。

I really appreciate any help that you guys can offer. 非常感谢你们能提供的任何帮助。

Thanks in advance! 提前致谢! (If I need to post any coding, I can do that, I just don't know what you guys would need, if anything, as far as coding examples for this...) (如果我需要发布任何编码,我可以做到,我只是不知道你们需要什么,就此而言,如果有编码示例……)

Python is different from PHP in that PHP executes your entire program separately for each hit to your website, whereas Python runs "worker processes" that stay resident in memory. Python与PHP的不同之处在于,PHP对您的网站的每次点击都会分别执行整个程序,而Python运行的“工作进程”将驻留在内存中。

You need some sort of web framework to do this work for you (you could write your own, but using someone else's framework makes it much easier). 您需要某种Web框架来为您完成这项工作(您可以编写自己的框架,但是使用其他人的框架会更加容易)。 Flask is an example of a light one; 烧瓶就是一个清淡的例子。 Django is an example of a very heavy one. Django是一个非常繁重的例子。 Pick one and follow that framework's instructions, or look for tutorials for that framework. 选择一个并遵循该框架的说明,或者寻找该框架的教程。 Since the frameworks differ, most practical documentation on handling web services with Python are focused around a framework instead of just around the language itself. 由于框架不同,因此有关使用Python处理Web服务的大多数实用文档都将重点放在框架上,而不仅仅是语言本身。

Nearly any python web framework will have a development server that you can run locally, so you don't need to worry about deploying yet. 几乎所有的python Web框架都会有一个可以在本地运行的开发服务器,因此您不必担心部署。 When you are ready to deploy, Apache will work, although it's usually easier and better to use Gunicorn or another python-specific webserver, and then if you need more webserver functionality, set up nginx or Apache as a reverse proxy. 当您准备好部署时,Apache将可以使用,尽管使用Gunicorn或其他特定于python的Web服务器通常更容易,更好,然后,如果您需要更多Web服务器功能,请将nginx或Apache设置为反向代理。 Apache is a very heavy application to use for nothing but wsgi functionality. Apache是​​一个非常繁重的应用程序,仅可用于wsgi功能。 You also have the option of deploying to a PaaS service like Heroku (free for development work, costs money for production applications) which will handle a lot of sysadmin work for you. 您还可以选择部署到像Heroku这样的PaaS服务(对于开发工作是免费的,对于生产应用程序来说是花钱的),它将为您处理大量的sysadmin工作。

As an aside, if you're not using virtualenv to set up your Python environment, you should look into it. 顺便说一句,如果您不使用virtualenv来设置您的Python环境,则应该对其进行研究。 It will make it much easier to keep track of what you have installed, to install new packages, and to isolate an environment so you can work on multiple projects on the same computer. 它将使跟踪已安装内容,安装新软件包以及隔离环境变得更加容易,因此您可以在同一台计算机上处​​理多个项目。

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

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