金字塔:如何在request.environ中设置SCRIPT_NAME [英] Pyramid: how to set SCRIPT_NAME in request.environ

查看:91
本文介绍了金字塔:如何在request.environ中设置SCRIPT_NAME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在nginx后面代理了一个Pyramid应用程序,为此我尝试在request.environ中设置SCRIPT_NAME.

I have a Pyramid app proxied behind nginx for which I'm trying to set SCRIPT_NAME in request.environ.

我尝试过:

  • 将其导出到外壳程序pserve中正在运行
  • 将其导出到外壳程序nginx中正在运行
  • 在金字塔配置文件中定义它
  • serve_forever()之前手动将其设置在
  • exporting it in the shell pserve is running in
  • exporting it in the shell nginx is running in
  • defining it in the Pyramid configuration file
  • manually setting it on gevent.wsgi.WSGIServer.environ before serve_forever()

我在上一步中定义的非标准值可用,但是SCRIPT_NAME始终为空,这似乎表明它正在被其他地方覆盖.

Non-standard values I define in the last step are available, but SCRIPT_NAME is always empty, which seems to indicate it's being overwritten from somewhere else.

如何设置?

推荐答案

看看repoze.vhm.

Have a look at repoze.vhm.

通常可以解决我所有的虚拟主机问题. (子路径,虚拟根目录等). repoze.vhm的最大优点是,您的金字塔应用程序可以完全不了解外部url和路径.不过,您一定要小心,在为站点/应用程序生成URL时使用request.route_url和其他方法(但这仍然是一种好习惯).

It usually solves all my virtual hosting problems. (subpath, virtual root etc...). Biggest advantage of repoze.vhm is, that your pyramid app can stay completely unaware of the external url und path. You do have to be careful though, that you use request.route_url and other methods when generating urls for your site/app (but that should be good practice anyway).

https://github.com/repoze/repoze.vhm

这篇关于金字塔:如何在request.environ中设置SCRIPT_NAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆