cpanel中的Python Flask app路由:只能访问root url [英] Python flask app routing in cpanel: can only access root url
问题描述
我在 cPanel 中设置了一个 python 应用程序.我已将应用程序 URL 设置为 backend
,当我查询 mydomain.com/backend/
时,它返回应用程序的根视图(这只是一个 htmlhello there").).
I have a python app set up in cPanel. I have set the app URL to backend
and when I query mydomain.com/backend/
it gives back the app's root view (which is just an html "hello there").
其余的端点是我需要的端点,但我在每个其他 URL 上返回 404
The rest of the endpoints are the ones I need but I get back a 404 on every other URL
@app.route('/')
def hello_world():
logger.debug("Hi there")
return "<h1 style='color:red'>Hi there</h1>"
@app.route('/test', methods=['POST','GET'])
def test():
logger.info("Got test request")
return {'ok' : 'success!'}
mydomain.com/backend/ --> Hi there
mydomain.com/backend/test --> 404
mydomain.com/backend/<any_other> --> 404
我敢打赌,在到达脚本之前,还有其他一些服务会返回 404.我在 public_html/.htaccess
中找不到任何对 backend/
的引用.依赖关系没问题(没有包抱怨).
I would bet there's some other service returning the 404 before reaching the script. I could not find any reference to backend/
in the public_html/.htaccess
. Dependencies are ok (no package complains).
我在服务器上的权限非常有限.任何指针将不胜感激.
My privileges on the server are very limited. Any pointers would be appreciated.
谢谢!
Ps 发现了一个类似的问题,但没有答案
Ps found a similar question with no answers
推荐答案
我们团队的一名成员通过添加一个新的子域并在那里设置 url 来解决这个问题.
A member of our team worked this out by adding a new subdomain and setting the url there.
因此,应用程序现在在 backend.mydomain.com/backend
上运行,而不是 mydomain.com/backend
,并且运行良好.
So instead of mydomain.com/backend
the app is running now at backend.mydomain.com/backend
and working just fine.
干杯
这篇关于cpanel中的Python Flask app路由:只能访问root url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!