[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
Logging

The server uses the standard Python logging module to log messages (if you're not using Python 2.3 or newer, you'll have to install the logging package yourself first). Logfiles appear in the "logs" directory. Logging configuration is in the "logging.cfg" file. There are a few loggers:
server使用标准的Python logging模块来记录日志信息(如果您没有使用python2.3或者更高版本,那么首先需要自行安装logging 模块)。 日志文件存储在”logs”目录中。Logging配置文件为 “logging.cfg”。有如下loggers:

"Snakelets.logger" is the logger that is used for server messages. Default logfile is "logs/server.log". It is a rotating logfile, 10 times 100Kb.
用于 server 信息。默认日志文件是 “logs/server.log”。rotating 日志文件,10次100Kb(应该如何翻译????)


      "Snakelets.logger.accesslog" is used for logging the web server requests (apache-style access log). Default logfile is "logs/access.log". It's a rotating logfile, 10 times 100Kb. The loglevel is set to 'NOTSET'. If you set it to 'CRITICAL', no access logging is performed (improves server speed; access logging slows it down).
      web请求日志(apache-style 访问日志)。默认日志文件”logs/access.log”。是 rotating 日志文件, 10次100Kb。Loglevle 设置为 ‘NOTSET’。如果设置为’CRITICAL’,没有访问日志处理(关闭日志处理可以改善性能)。

      "Snakelets.logger.stdout" and "Snakelets.logger.stderr" are the logger adapters for the standard output and standard error messages. These messages are printed on the console but are also written to "logs/server_console.log"
      用来纪录 标准输出 和 标准错误 信息。这些信息将被输出到控制台同时也被写入到 ‘logs/server_console.log’中。



You can use the logging facility in your own code by doing:
你可以很容易的通过如下代码使用logging:
  1. import logging
  2. log=logging.getLogger("Snakelets.logger")
  3. log.debug("my debug message")
复制代码
User libraries / modules

If you want to use a library or module from within several webapps, you don't have to include it in every webapp directory. There is a special directory "userlibs" in which you can place your modules and packages that you want to install. Snakelets adds this directory to the module search path, so you can import anything in it in your webapps without using nasty prefixes.
如果你想在一些webapp中使用 库 或者 模块,你并不需要将他们include到每一个webapp目录中。这里有一个特殊的目录:”userlibs”,你可以放置你所需要的模块或者是 package。Snakelets将此目录添加到检索路径中,你可以在任何webapp中直接调用他们从而避免使用令人厌恶的路径前缀。

You can also easily upgrade libraries this way, just put the new version in userlibs instead of the older version and all your webapps that import it will instantly use the new code the next time you start the server.
您可以将更新版本的 库 文件放入到 userlibs目录中来代替就版本,从而很容易的进行升级,server将在下一次启动的时候载入新的文件。

TOP

Virtual Hosts

Snakelets supports virtual hosting (based on hostnames). To enable this feature you have to edit the Virtual Host configuration. It tells the server what web applications to load and to what host names they must be connected. If you have different hostnames that point to the same IP address you are able to serve different web sites this way (this only works with HTTP 1.1 browsers, but most browsers are). The configuration file is webapps/__init__.py (the webapp module init file). It contains four configuration items:
Snakelets 提供 virtual hosting(基于hostnames)。要启动这个功能您需要对Virtual Host configuration进行配置。这将告诉server哪些web 应用程序应该被载入,哪些主机名必须被连接。如果你有不同的主机名指向同一个IP,那你可以通过这种方式提供不同的web sites 服务(这只工作在支持 HTTP 1.1 的浏览器,其实大部分浏览器都支持)。配置文件是 webapps/__init__.py 。包括四个 配置item :


      ENABLED - set this to True to enable virtual hosts. Setting it to False disables this feature and reverts back to out-of-the-box startup (see above).
      ENABLED-设置这项为True将开启虚拟主机。设置为False将关闭虚拟主机并回到out-of-the-box状态(见下文)。

      virtualhosts - a mapping of host names to a sequence of web application names that will be connected to the specified hostname. If a web application is not mentioned for any virtual host, it won't be loaded. A web app may be connected to multiple vhosts.
      virtualhosts – 主机名,映射到web应用程序名序列中,将被连接到指定的主机名。如果一个web应用程序没有提及任何虚拟主机,他将不会被载入。Web app可能被连接到复合的vhost。

      webroots - a mapping of host names to the name of the web app that will be mapped in the URL root ( '/' ) of the server on that virtual host. The web root hosts must be known virtualhosts specified in the virtualhosts.
      webroots – 被映射到 URL跟目录的主机名(‘/’)

      aliases - a mapping of vhost-alias name to real-vhost name (this avoids duplicate loading of webapps).
      aliases – 虚拟主机别名,映射到真实主机名(避免重复载入webapps)。

      defaultvhost - the name of the default virtual host that will be used when the browser doesn't send a 'Host' header.
      默认主机名,当浏览器没有发送’Host’header是起作用。



Every vhost can have a different list of webapps that are deployed on it, but a webapp can also be deployed on multiple vhosts at the same time. However, all deployed instances will be separate, unrelated copies of the webapp: if you deploy a webapp on multiple vhosts, it will be created for each vhost, and the init function will be invoked once for every copy.
虽然每个vhost都可以拥有不同的webapp 被deploy(这个单此在这里应该如何翻译????)过的列表,但是每一个webapp也可以同时被不同的vhost deploy。然而所有已经deploy的 实例将被分开并且被创建到每一个vhost,init函数将在每一份copy中被运行一次。

Starting the server

If the virtual host config is in place, the Snakelet server is best started using the provided serv.py script. Just execute this and you're ready to go! Notice that the web applications that you configured in the virtual host config are installed automatically, any other web applications in the webapps directory are ignored. The parameters to snakeserver.server.main are:
如果已经配置好虚拟主机,Snakelets服务将通过提供的serv.py脚本很好的运行。只运行这个脚本就可以了。您对web应用程序的配置在虚拟主机中是自动被载入的,其他的web 应用程序目录将被忽略。传递给 snakeserver.server.main的参数是:


      HTTPD_PORT - the port the http server will be listening on (default=9080).
      HTTPD_PORT – http服务监听端口

      externalPort - the port the server is visible on from the outside world (default=same as HTTPD_PORT). If you're running behind a forwarding proxy you may need to set this. 'External' hostnames are handled by the virtual host configuration.
      externalPort – 外部服务端口(默认同HTTP_PORT相同)。如果通过forwarding proxy运行,您可能需要设置虚拟主机的“外部”主机名。

      bindname - the hostname the server will bind on, None (default) means only the current host
      bindname – 服务绑定主机名,None为默认。

      serverURLprefix - URL prefix for all urls that this server uses (for instance, "/snakelets). Default is '' (empty). Internally it will be molded into the form "/prefix"; slashes will be added/stripped automatically if required.
      serverURLprefix – URL前缀,用于所有urls(比如,”/snakelets)。默认为”(empty)。他会被植入到”/prefix”中,斜线将会被自动的添加或者删除。

      debugRequests - should the incoming requests and headers be printed? Default is False (boolean).
      debugRequests – 打印 incoming 请求 和 headers ? 默认False。

      precompileYPages - should all Ypages be precompiled to find possible errors early? Default is True (boolean). You may want to set this to False to allow faster startup times, but then you won't find out if an Ypage can't compile until the page is actually requested. (This feature needs Python2.3+)
      precompileYPages – 所有Ypage被重新编译以便更早的发现错误?默认为 True 。您可能相关掉此项来提高速度,但你马上会发现只有你的页面被请求的时候他才会被编译。(这个功能需要Python2.3或更高版本)。

      writePageSource - should the generated Ypage source code be written to a file in the tmp directory? Default is False (boolean). You may want to set this to True for easier Ypage debugging.
      writePageSource – 将产生Ypage源代码并写入到tmp目录下的文件里。默认为False。您可以打开此功能以便调试。



It is also possible to use the monitor.py script. This script is designed to run on Linux, and will check if the server is active. If it's not active (or hanging) the monitor script will restart the Snakelets server (as a daemon process in the background). After starting the server it does not check anymore if it's still running, so you will have to create your own mechanism to be sure that a stopped (crashed?) server is restarted.
也可以使用monitor.py脚本。设计这个脚本用来在Linux上运行,并用来检测server是否被激活。如果没有被激活(或者 挂接?)监控脚本将会重新启动Snakelets server (像是后台的 daemon处理)。在server启动之后他将不进行任何检测出飞他仍然在运行,因此你需要创建你自己的机制来确认已经停止的(崩溃的?)server 被重新启动。

TOP

Apache?

...is not needed: Snakelets contains its own multithreaded web server. But if you still want to use Apache, you can use mod_proxy or mod_rewrite to let Apache forward certain requests to a running snakelets server behind it. Plans exist to develop a snakelets module for tighter integration in Apache, and for more performance. But for now, you'll have to use mod_proxy (or mod_rewrite).
Apache?
…没有必要使用:snakelets 包括自己特有的 multithreaded(不知道是虾米意思) web server。不过如果你坚持要用Apache的话,你可以使用mod_proxy 或mod_rewrite 来让apache指向某些来自snakelets的请求。正在计划开发一个snakelets的模块来让apache和snakelets紧密结合起来,并使其功能更加完善。但是目前您还只能够使用mod_proxy 或者 mod_rewrite。


Configuring Apache; bottom line: Set up apache to reverse-proxy everything after snake/ to Snakelets.
配置Apache;概要:安装 apache 来 reverse-proxy(??什么意思??)snake/下的所有东西到Snakelets。(这段好像是说翻转代理所有snake/目录下的东西到 Snakelets,使得Snakelets可以解析此目录下的所有页面)

Warning: as the Apache manual also states, regarding the use of proxies: please secure your Apache configuration: do not let it become an open proxy server!
警告:在Apache参考中关于proxies的描述:
请注意Apache的配置安全问题:不要让你的apache成为一个开放的proxy server

Edit your Apache config file. Make sure that mod_proxy is loaded in the LoadModule section.
编辑你的Apache 配置文件。确认mod_proxy在LoadModule段落中被载入。

Configure the forwarding to the Snakelets server:
配置 forwarding 到 Snakelets server:
  1. ProxyRequests Off
  2. ProxyPass /snake/ http://localhost:9080/snake/
  3. ProxyPassReverse /snake/ http://localhost:9080/snake/
复制代码
This example forwards all requests starting with '/snake/' to Snakelets. You can also configure a dedicated virtual host, for example:
例子是指向 /snake/ 目录的,你也可以设置专门的虚拟主机:
  1. <VirtualHost snakelets.host.domain>;
  2.   ServerName snakelets.host.domain
  3.   ProxyRequests Off
  4.   ProxyPass / http://localhost:9080/
  5.   ProxyPassReverse / http://localhost:9080/
  6. </VirtualHost>;
复制代码
Now all requests to this hostname will be passed to Snakelets.
现在所有的请求会被发送到snakelets。

Then run Snakelets where you set (in serv.py) bindname='localhost', serverURLprefix='/snake/' and externalPort=80. If you use the virtualhost mapping, the serverURLprefix is empty.
在serv.py中设置bindname='localhost', serverURLprefix='/snake/' , externalPort=80 。如果您使用virtualhost mapping , 那么servURLprefix 为空。

Note: if you are using mod_cache, you must tell it to not cache the Snakelets urls! This can be done like this:
注意:如果您使用 mod_cache,那么必须说明不缓存 Snakelets urls !设置如下:
  1.     <IfModule mod_cache.c>;
  2.       CacheDisable /your-snakelet-url-base
  3.     </IfModule>;
复制代码
If you find that your URLs are not correct in Snakelets, you also have to enable virtual hosting in Snakelets (see below) and create a virtual host entry for the 'correct' hostname (i.e. the hostname that is used in your URLs). (You can still use a different bindname such as "localhost".
    如果您的URLs在snakelets中不正确,你也必须在snakelets中开启虚拟主机(见下文)并且为正确的主机名开放入口(也就是在您的URLs中所使用的主机名)。(您仍然可以使用不同的bindname,比如”localhost”)。

TOP

返回列表