简体   繁体   English

在实时服务器上开始使用金字塔

[英]Getting started with pyramid on a live server

I have successfully run the simplest pyramid app in my local virtual environment. 我在本地虚拟环境中成功运行了最简单的金字塔应用程序 I am now working on this tutorial but I am trying to take it a step further by running it on my personal hosting site that I use to mess around with stuff like this. 我现在正在研究这个教程,但我试图通过在我的个人托管网站上运行它来更进一步,我用它来搞乱这样的东西。

My question is. 我的问题是。 What do I pass to make_server(host, port, app) as parameters and what url do I go to to check to see if it is running? 我将什么传递给make_server(host, port, app)作为参数以及我要检查哪些URL以查看它是否正在运行? I know it's a simple question, I'm just not used to this kind of work and the documentation isn't helping me. 我知道这是一个简单的问题,我只是不习惯这种工作而且文档没有帮助我。

Bonus Points: 奖励积分:

What are the differences between running this on a local virtual environment and on proper hosting in terms of this kind of web application? 在本地虚拟环境中运行此操作与在此类Web应用程序方面正确托管之间有什么区别?

important edit: my provider is bluehost and since I don't have a dedicated IP, I am not allowed to open my own ports, which makes me wonder if this is even possible 重要的编辑:我的提供商是bluehost,因为我没有专用的IP,我不允许打开我自己的端口,这让我想知道这是否可能

In fact, hosting a Python application on a "real" webserver is quite different from running it on you local machine: locally you rely on a small webserver which is often built into the framework - however, that webserver often has limitations (for example, it may only execute requests in a single thread). 实际上,在“真实”的Web服务器上托管Python应用程序与在本地计算机上运行它完全不同:本地您依赖于通常内置于框架中的小型Web服务器 - 但是,该Web服务器通常具有局限性(例如,它可能只在单个线程中执行请求)。 Some frameworks (Django) explicitly state that their built-in server should only be used for development. 一些框架(Django)明确声明他们的内置服务器应该只用于开发。

In a production environment a Python application is usually served by a "industrial-grade" webserver, such as Apache or Nginx, which takes care of such issues as binding to low ports, dropping privileges, spawning multiple "worker" processes, dealing with virtual hosts, sanitizing malformed requests etc. The Python application is then run within the web server using something like mod_wsgi or fcgi for Apache or uwsgi for Nginx. 在生产环境中,Python应用程序通常由“工业级”Web服务器提供服务,例如Apache或Nginx,它负责解决诸如绑定到低端口,删除权限,产生多个“工作”进程,处理虚拟等问题。主机,清理格式错误的请求等。然后使用mod_wsgifcgi for Apache或uwsgi for Nginx在Web服务器中运行Python应用程序。 Alternatively, your application runs as a separate process listening on 127.0.0.1:6543 (just like you do it locally) and the "front" web server proxies all requests to your application and back. 或者,您的应用程序作为单独的进程运行,侦听127.0.0.1:6543(就像您在本地执行一样),“前”Web服务器代理对您的应用程序的所有请求并返回。

The point is: It may be tricky/impossible to host a Python application on a general purpose shared hosting unless your provider has explicit support for hosting WSGI applications (ask them for instructions) 重点是:在通用共享主机上托管Python应用程序可能很棘手/不可能,除非您的提供程序明确支持托管WSGI应用程序(询问他们的说明)

Another point: for $5/mo these days you can get a nice dedicated virtual machine where you can install whatever your want and not share it with anyone. 另一点:这些天你可以获得5美元/美元的专用虚拟机,你可以安装任何你想要的东西,而不是与任何人分享。 Hosting a Python website is much easier this way then dealing with shared hosting. 托管Python网站比处理共享托管更容易。

Ahh, and to answer the question: in a real production application the last 2 lines of the example: 啊,并回答这个问题:在实际的生产应用程序中,示例的最后两行:

server = make_server('0.0.0.0', 8080, app)
server.serve_forever()

will not be used - instead you configure the webserver so it knows that the app variable contains your wsgi application. 将不会使用 - 而是配置Web服务器,以便它知道app变量包含您的wsgi应用程序。 Refer to the next chapter in the docs for a more realistic example. 有关更实际的示例,请参阅文档的下一章

Try running the site on a free account on PythonAnywhere, its the simplest to get started with. 尝试在PythonAnywhere上的免费帐户上运行该站点,这是最简单的入门。

You can simple make a git repo from your files on github, and then clone then on PythonAnywhere (I mention a host in specific, because you want to know how to run something on a host, and I have found it to be the most easy one). 你可以在github上简单地从你的文件中创建一个git repo,然后在PythonAnywhere上克隆(我特别提到了一个主机,因为你想知道如何在主机上运行某些东西,我发现它是最简单的一)。 As for specifics, just ask on their forums, they will help you out. 至于细节,只要在他们的论坛上询问,他们会帮助你。

I initially made a django site there, and it was was my first online app, and I learned a decent amount. 我最初在那里制作了一个django网站,这是我的第一个在线应用程序,我学到了不错的数量。

Secondly, running your app online and on your own computer has very few differences, and these differences vary from webhost to webhost. 其次,在线和在您自己的计算机上运行您的应用程序的差异很小,这些差异从webhost到webhost不等。 So, you are going to have to be a bit more specific about what you want to know. 因此,您将需要更具体地了解您想要了解的内容。

Hope this helps. 希望这可以帮助。

You would be using makeserver for test deployment. 您将使用makeserver进行测试部署。 In this case you often wrap a little runserver-Script, like this (as the tutorial also points out): 在这种情况下,你经常包装一个小的runserver-Script,就像这样(正如教程也指出的那样):

#!/bin/env python
from wsgiref.simple_server import make_server
from yourapp.core import app # whereever your wsgi app lives

if __name__ == '__main__':
     server = make_server('0.0.0.0', 6547, app)
     print ('Starting up server on http://localhost:6547')
     server.serve_forever()

If you want to deploy to Apache you need the mod_wsgi module. 如果要部署到Apache,则需要mod_wsgi模块。 I would recommend getting a hoster with nginx or lighthttpd support. 我建议获得一个支持nginx或lighthttpd的托管服务商。 WSGI applications can very conveniently deployed using the uwsgi module in combination with virtualenv. 使用uwsgi模块和virtualenv可以非常方便地部署WSGI应用程序。

If your hoster doesn't allow you to open ports, you can configure uwsgi to use unix sockets. 如果您的主机不允许您打开端口,则可以配置uwsgi以使用unix套接字。

I wrote a blog post explaining how to deploy Django behind uwsgi + nginx once, you might want to use this as a starting point for playing around with deployment settings: http://blog.johannesklug.de/2012/11/27/deploying-django-behind-nginx-with-uwsgi-and-virtualenv/ 我写了一篇博客文章,解释了如何在uwsgi + nginx之后部署Django,您可能希望将其作为开始使用部署设置的起点: http//blog.johannesklug.de/2012/11/27/deploying -django-背后nginx的与- uwsgi和-的virtualenv /

Note: the same app object you feed into make_server will you used by uwsgi to start its worker process and open a socket. 注意:您输入make_server的相同app对象将由uwsgi用于启动其工作进程并打开套接字。

A sample configuration (not tested but excerpted from my blog post) for uwsgi: uwsgi的示例配置(未经过测试但摘自我的博文):

# uwsgi.ini
[uwsgi]
# path to where you put your project code
chdir=/home/project/project

# if the app object resides in core.py
module=core:app

# this switch tells uwsgi to spawn a master process,
# that will dynamically spawn new child processes for
# server requests
master=True
# uwsgi stores the pid of your master process here
pidfile=/home/project/master.pid
vacuum=True
# path to your virtual environment, you should be using virtualenv
home=/home/project/env/
# path to log file
daemonize=/home/project/log
# this is where you need to point nginx to,
# if you chose to put this in project home make
# sure the home dir is readable and executable by
# nginx
socket=/tmp/uwsgi.sock

Sample config for nginx: nginx的示例配置:

server {
    listen       80;
    server_name  yourserver.example.org;

    location / {
        uwsgi_pass unix:///tmp/uwsgi.sock;
        include uwsgi_params;
    }
}

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

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