【发布时间】:2018-02-04 23:53:56
【问题描述】:
如今有如此多的 Web 应用程序在它们自己的微服务器上运行,因此很难在共享托管平台上实现它们。应用程序侦听您可以自定义或反向代理的专用端口,但共享主机通常只打开 80 和 443。
例如,方便的基于 Web 的编辑器 ICEcoder 是一个 PHP 应用程序,因此您只需将文件放到一个目录中即可。但是,Cloud9 编辑器运行它自己的服务器。您可以自定义端口,但同样不能运行反向代理。
我有使用 PHP 或 Python CGI 脚本作为中介的想法。比如:
www.mydomain/mydirectory/middleman.py
from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse, json
# hpyothetical apache api
import apache
parsed_path = urlparse.urlparse(self.path)
response = apache(url=parsed_path, port=8080)
sendStuffBack(response)
这对于 Apache 是否可行?我将如何实现它?
编辑: 这是我根据@grawity 的回答所做的。
helloflask.py
#!/usr/bin/env python
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
middle.py
#!/usr/bin/env python
print ("Content-Type: text/html")
print()
import requests
#response = requests.get("http://localhost:5000")
response = requests.get("http://localhost:8888/token=8a387fe88d662e2568f9b8ec2398191452492e7184536670")
print(response.text)
【问题讨论】:
-
您可以编辑您的问题以包含一个问题吗?
-
@Spiff 这更好吗? :)
标签: python web-applications port reverse-proxy shared-hosting