当前位置: 首页 > 知识库问答 >
问题:

为什么我的Ubuntu Apache服务器上的Flask应用程序被拒绝了?

景俊语
2023-03-14

环境:

Python 3.7.5

烧瓶1.1.2

托管公司:Ionos

类型:带有Plesk面板的ubuntu上的VPS。

Ubuntu 18.04.5 LTS,代号:仿生

我有一个网站域名。通用域名格式。例如,我需要子域“dashboard.domain.com”上的仪表板。我的服务器是一个虚拟服务器,使用“虚拟主机”和apache作为我在这个VPS上的所有域名。我正试图在带有子域的ubuntu服务器上部署我的python flask应用程序。我在服务器上安装了必要的软件包(wsgi、flask等)

之后,我做了以下工作:

>

域的文件。com位于:

/var/www/vhosts/domain.com/httpdocs/

我在域中创建了一个文件夹“dashboard”。com文件夹:

/var/www/vhosts/domain.com/dashboard

在此文件夹中,我上传了Flask应用程序的所有文件:

dashboard/
  - forms.py
  -__init__.py
  -models.py
  -myproj
  -routes.py
  -static/
  -templates/
  
dashboard.wgsi
favicon.ico

我创建了仪表板。wgsi文件:

#!/usr/bin/python导入系统导入日志系统。标准输出=系统。stderr日志记录。基本配置(流=系统标准)系统。路径插入(0,“/var/www/vhosts/domain.com/dashboard/”)

从仪表板导入应用程序作为应用程序。密钥='Paris@TOTO'

和初始化。py文件:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
import os

app = Flask(__name__)
print(app)
SECRET_KEY = os.urandom(32)
app.config['SECRET_KEY'] = SECRET_KEY
app._static_folder = os.path.abspath("dashboard/static")
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://dashboard:toto@toto@218.218.88.98/db_alejo'

db_mysql = SQLAlchemy(app)
login_manager = LoginManager(app)
login_manager.login_view='login'
login_manager.login_message_category='info'
import routes



if __name__ == "__main__":
    app.run(host='0.0.0.0',threaded=True,port=80, debug=True)

我在/etc/apache2/sites-available中创建了conf文件“dashboard.conf”/

 ServerAdmin admin@domain.com

 RewriteEngine On

 RewriteCond %{HTTP_HOST} !^www\. [NC]

 RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 ServerName dashboard.domain.com

 Redirect "/" "https://dashboard.domain.com/"

 WSGISocketPrefix run/wsgi

 DocumentRoot /var/www/vhosts/domain.com/dashboard

 WSGIScriptAlias / /var/www/vhosts/domain.com/dashboard/dashboard.wsgi
 WSGIApplicationGroup %{GLOBAL}
 <Directory /var/www/vhosts/domain.com/dashboard/>
     WSGIProcessGroup dashboard
     WSGIApplicationGroup %{GLOBAL}
     Options +Indexes +FollowSymLinks +Includes +ExecCGI
     AllowOverride All
     Require all granted

     <Files dashboard.wsgi>
         Require all granted
         Satisfy Any
     </Files>

 </Directory>
 Alias /static /var/www/vhosts/domain.com/dashboard/dashboard/static
 <Directory /var/www/vhosts/domain.com/dashboard/dashboard/static/>
     Require all granted
 </Directory>
     Alias /templates /var/www/vhosts/domain.com/dashboard/dashboard/templates
 <Directory /var/www/vhosts/domain.com/dashboard/dashboard/templates/>
     Require all granted
 </Directory>
 ErrorLog ${APACHE_LOG_DIR}/error-dashboard.log
 LogLevel warn
 CustomLog ${APACHE_LOG_DIR}/access-dashboard.log combined
 Options Indexes FollowSymLinks Includes ExecCGI

我在 /etc/apache2/中启用这个新的虚拟主机:

sudo a2ensite仪表板

我重新启动了Apache:

sudo服务apache2重启

然后,当我测试url的仪表板时。领域com“在我的浏览器中,我得到ERR\u CONNECTION\u拒绝错误。

所以我去检查/var/log/apache2中的错误日志文件

access-dashboard.log
access.log
error-dashboard.log
error.log
etc...

通道日志,访问仪表板。日志和错误仪表板。日志为空!

但是错误。日志显示:

[Sun Jun 20 09:18:05.319394 2021] [core:notice] [pid 123611:tid 140042122066880] AH00094: Command line: '/usr/sbin/apache2'
[Sun Jun 20 09:29:10.784759 2021] [mpm_event:notice] [pid 123611:tid 140042122066880] AH00491: caught SIGTERM, shutting down
[Sun Jun 20 09:29:10.871612 2021] [ssl:warn] [pid 123886:tid 139941449337792] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:29:10.872664 2021] [suexec:notice] [pid 123886:tid 139941449337792] AH01232: suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sun Jun 20 09:29:10.913299 2021] [ssl:warn] [pid 123887:tid 139941449337792] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:29:10.916884 2021] [mpm_event:notice] [pid 123887:tid 139941449337792] AH00489: Apache/2.4.29 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1 mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Sun Jun 20 09:29:10.916930 2021] [core:notice] [pid 123887:tid 139941449337792] AH00094: Command line: '/usr/sbin/apache2'
[Sun Jun 20 09:31:49.048780 2021] [mpm_event:notice] [pid 123887:tid 139941449337792] AH00491: caught SIGTERM, shutting down
[Sun Jun 20 09:31:49.128428 2021] [ssl:warn] [pid 124113:tid 140041460632512] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:31:49.129369 2021] [suexec:notice] [pid 124113:tid 140041460632512] AH01232: suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sun Jun 20 09:31:49.157978 2021] [ssl:warn] [pid 124114:tid 140041460632512] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:31:49.160524 2021] [mpm_event:notice] [pid 124114:tid 140041460632512] AH00489: Apache/2.4.29 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1 mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Sun Jun 20 09:31:49.160557 2021] [core:notice] [pid 124114:tid 140041460632512] AH00094: Command line: '/usr/sbin/apache2'
[Sun Jun 20 09:32:52.399045 2021] [mpm_event:notice] [pid 124114:tid 140041460632512] AH00491: caught SIGTERM, shutting down
[Sun Jun 20 09:32:52.474928 2021] [ssl:warn] [pid 124199:tid 139647707720640] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:32:52.475928 2021] [suexec:notice] [pid 124199:tid 139647707720640] AH01232: suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sun Jun 20 09:32:52.503028 2021] [ssl:warn] [pid 124200:tid 139647707720640] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:32:52.505368 2021] [mpm_event:notice] [pid 124200:tid 139647707720640] AH00489: Apache/2.4.29 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1 mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Sun Jun 20 09:32:52.505401 2021] [core:notice] [pid 124200:tid 139647707720640] AH00094: Command line: '/usr/sbin/apache2'
[Sun Jun 20 09:48:02.252928 2021] [mpm_event:notice] [pid 124200:tid 139647707720640] AH00491: caught SIGTERM, shutting down
[Sun Jun 20 09:48:02.331049 2021] [ssl:warn] [pid 125048:tid 140143670598592] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:48:02.332062 2021] [suexec:notice] [pid 125048:tid 140143670598592] AH01232: suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sun Jun 20 09:48:02.359902 2021] [ssl:warn] [pid 125049:tid 140143670598592] AH01909: default-218_218_43_88:443:0 server certificate does NOT include an ID which matches the server name
[Sun Jun 20 09:48:02.362378 2021] [mpm_event:notice] [pid 125049:tid 140143670598592] AH00489: Apache/2.4.29 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1 mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Sun Jun 20 09:48:02.362414 2021] [core:notice] [pid 125049:tid 140143670598592] AH00094: Command line: '/usr/sbin/apache2'

有人能帮我解决这个问题吗?

共有2个答案

栾烨华
2023-03-14

这表明Apache的SSL设置存在错误,根据本文的说法,这是一个很容易解决的问题

您应该将服务器重命名为localhost,例如:

ServerName localhost

我想补充一点,我无法重现你的错误,我得到的只是警告,但我的应用程序似乎运行良好。我给出这个答案的目的不仅是为了帮助,而且是为了验证这个问题可以通过这种方式解决。

请回来告诉我们进展如何))

岑畅
2023-03-14

您有一个重定向到https:/。。。但您不会显示虚拟主机在端口443上侦听:

Redirect "/" "https://dashboard.domain.com/"
 类似资料:
  • 下面是我请求的权限。 com.anddoes.launcher.permission.update_count,com.google.android.c2dm.permission.receive,com.google.android.finsky.permission.bind_get_install_referr_service,com.google.android.providers.gsf

  • 在尝试使用Apache mod\u wsgi运行Flask时,我已经尝试了很多事情,但都非常沮丧。 基本上,我已经完成了以下教程: http://flask.pocoo.org/docs/deploying/mod_wsgi/#installing-mod-wsgihttp://www.lonesomedev.com/?p=169 但在浏览器上,我得到了以下错误: 访问禁止! 您无权访问请求的对象

  • 我正试图将从gallery中选择的图像上传到Springboot服务器,但当我的服务试图发布该图像时,我的文件路径权限被拒绝。我已经向我的AndroidManifest添加了以下权限: 然后,我请求允许实时选择图像,然后我想把它放在一个膨胀的视图中,在那里用户可以提供关于图像的更多细节,然后把它添加到一个报告中,我将稍后发布。 我在谷歌上发现这个错误的每一个点击都会指向一个不要求实时许可的人,但我

  • 我想使用vault服务器来存储机密并将其部署在openshift上。 我编写了这个 dockerfile,构建了映像并将其推送到 openshift 注册表,并从此映像流创建了一个部署: 以下是配置: 我创建了一条到8200端口的路径。当我从vault-server pod内部使用vault CLI时,它工作正常,我可以登录、配置等。当我在本地计算机上使用openshift cli将端口8200转

  • 我有一个带有Python脚本的Node.js应用程序,我正试图将它部署到Heroku。 每次尝试添加buildpack,都会被拒绝。 远程:找不到满足要求的版本pywin32==224(来自-r/tmp/build_ebad00F3B8D3C9B4B03965F0D0924E7a/requirement.txt(第57行))(来自版本:)远程:找不到与pywin32==224(来自-r/tmp/b

  • 我使用Apache HTTPDmod_wsgi运行一个烧瓶应用程序。该应用程序运行良好,但每次访问页面时,error_log都会出现错误。(我正在尝试优化应用程序)。 错误为:AH01630:客户端被服务器配置拒绝:/apps/apache/httpd_alass/htdocs/ HTTPD.conf 包含 即使在WSGI正确提供此应用程序之后,为什么会在error_log中写入错误以及如何修复它