【问题标题】:Deploying flask app on cpanel, INTERNAL SERVER ERROR when changing requesting other than base url在 cpanel 上部署烧瓶应用程序,更改基本 URL 以外的请求时出现内部服务器错误
【发布时间】:2020-06-02 00:19:32
【问题描述】:

我想在共享主机上部署我的 flask-restx 应用程序。由于我是部署的初学者,因此我遵循了 youtube 上的视频教程。 我是按照这个tutorial一步一步做的。 对于那些不想通过教程的人,我正在编写步骤:

  1. 我从 Python cPanel 创建了一个应用程序 Initial set up in Cpanel
  2. 然后我打开终端并通过“pip install flask”更改了我的 venv 并安装了烧瓶
  3. 项目结构
filas_folder/
├──public
├──tmp
│   └──restart.txt 
├──app.py
└──passenger_wsgi.py

app.py 看起来像

from flask import Flask
app = Flask(__name__)

@app.route("/")
def main_():
        return "flask is running"

@app.route("/user")
def main_2():
        return "user is running"



if __name__ == "__main__": app.run()
  1. 从 cpanel 重启应用

passenger.py 看起来像

import imp
import os
import sys


sys.path.insert(0, os.path.dirname(__file__))

wsgi = imp.load_source('wsgi', 'app.py')
application = wsgi.app

当我打开 www.example.com

flask is running

但是当我打开 www.example.com/user

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

我的系统有 cloudlinux 并使用 apache 服务器。这不是第一次部署。许多 wordpress 和静态网站都在服务器上运行。 我在 /usr/local/apache/logs/error_log 打开了 apache 日志 我收到错误“由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,请使用 'LimitInternalRecursion' 增加限制。使用 'LogLevel debug' 获取回溯。引用者“http://example.com/user

【问题讨论】:

标签: python flask cpanel web-deployment mod-wsgi


【解决方案1】:

将以下内容添加到 .htaccess 文件的顶部:

RewriteEngine on  
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]

此信息来自:https://stackoverflow.com/a/63971427/10122266

【讨论】:

  • 如果是重复的问题,vote to close 和/或在您earn 足够reputation 后发表评论。如果没有,为这个特定问题定制答案。那么这是一个很好的答案,无需请求许可即可忽略评论规则。但是,您现在确实拥有评论权限,所以如果您仍然认为这应该是评论,请把它变成一个评论。
  • 因为你知道你没有的评论权限,所以你甚至可以把它说出来。您知道规则 meta.stackexchange.com/questions/214173/… 。在这种情况下,请不要决定滥用不同的机制(答案)来处理它不适合且不允许您做的事情。
猜你喜欢
  • 2019-11-09
  • 2017-12-23
  • 2019-04-01
  • 1970-01-01
  • 2011-11-14
  • 1970-01-01
  • 2014-08-06
  • 2021-12-20
  • 2022-01-06
相关资源
最近更新 更多