在服务器上运行 Python 脚本(是否必须位于 /cgi-bin/ 中)?
现在我有一个脚本,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 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
简短的回答是,是的。我不是这方面的专家,但我知道许多框架完全可以完成您刚才所做的事情(例如 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.