在服务器上运行 Python 脚本(是否必须位于 /cgi-bin/ 中)?

发布于 2024-09-09 01:59:29 字数 206 浏览 3 评论 0原文

现在我有一个脚本,

http://www.example.com/cgi-bin/foo?var1=A&var2=B

有没有办法让它在 cgi-bin 目录之外运行?就像我可以有

http://www.example.com/foo/?var1=A&var2=B

Right now I have a script thats

http://www.example.com/cgi-bin/foo?var1=A&var2=B

Is there a way that I can have it run outside of the cgi-bin directory? Like could I have

http://www.example.com/foo/?var1=A&var2=B

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葵雨 2024-09-16 01:59:29

在 Apache 中,您可以使用 httpd.conf(或保存您的配置的任何文件)中的 ScriptAlias 指令更改包含可执行脚本的目录。

您还可以使用 mod_rewrite 重写 URL 以指向您要执行的脚本。如果您愿意,Mod_rewrite 还允许您以 URL 的形式传递变量和内容,例如

www.example.com/foo/A/B/ -> www.example.com/foo?var1=A&var2=B

In Apache you can change the directories that can contain executable scripts with the ScriptAlias directive in httpd.conf (or whatever file holds your configuration).

You can also use mod_rewrite to rewrite URLs to point to the scripts you want to execute. Mod_rewrite also allows you to pass variables and stuff in the form of URLs if you like that, e.g.

www.example.com/foo/A/B/ -> www.example.com/foo?var1=A&var2=B

Smile简单爱 2024-09-16 01:59:29

简短的回答是,是的。我不是这方面的专家,但我知道许多框架完全可以完成您刚才所做的事情(例如 Ruby on Rails)。其中很大一部分与服务器路由 URL 的方式有关。尝试查找服务器上的文档。

Short answer, yes. I'm no expert on this, but I know of a number of frameworks that do exactly what you just did (e.g. Ruby on Rails). A lot of it has to do with how your server routes URLs. Try looking up the documentation on your server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文