【问题标题】:Why my Flask application on my Ubuntu Apache server get ERR_CONNECTION_REFUSED?为什么我的 Ubuntu Apache 服务器上的 Flask 应用程序得到 ERR_CONNECTION_REFUSED?
【发布时间】:2021-09-04 08:19:21
【问题描述】:

环境:

Python 3.7.5

烧瓶 1.1.2

托管公司:Ionos

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

Ubuntu 18.04.5 LTS,代号:仿生

我有一个网站 domain.com。例如,我需要子域“dashboard.domain.com”上的仪表板。 我的服务器是使用 "virtual hosts" 和 apache 的虚拟服务器,用于我位于此 VPS 上的所有域名。 我正在尝试在带有子域的 ubuntu 服务器上部署我的 python 烧瓶应用程序。 我在我的服务器上安装了必要的软件包(wsgi、flask 等)

之后,这就是我所做的:

  1. 我创建了一个子域“dashboard.domain.com”

  2. domain.com 的文件位于那里:

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

我在 domain.com 文件夹中创建了一个文件夹“仪表板”:

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

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

dashboard/
  - forms.py
  -__init__.py
  -models.py
  -myproj
  -routes.py
  -static/
  -templates/
  
dashboard.wgsi
favicon.ico
  1. 我创建了dashboard.wgsi 文件:

    #!/usr/bin/python 导入系统 导入日志 sys.stdout = sys.stderr logging.basicConfig(流=sys.stderr) sys.path.insert(0,"/var/www/vhosts/domain.com/dashboard/")

    从仪表板导入应用程序作为应用程序 application.secret_key = 'Paris@TOTO'

init.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)
  1. 我在 /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
    
  2. 我在 /etc/apache2/ 中启用了这个新的虚拟主机:

    sudo a2ensite 仪表板

  3. 我重新启动了 Apache:

    sudo 服务 apache2 重启

然后,当我在浏览器中测试 url 'dashboard.domain.com' 时,我收到 ERR_CONNECTION_REFUSED 错误。

于是我去查看/var/log/apache2中的错误日志文件

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

access.log、access-dashboard.log 和 error-dashboard.log 为空!

但error.log显示:

[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'

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

【问题讨论】:

    标签: python apache flask mod-wsgi


    【解决方案1】:

    你有一个重定向到 https:/... 但你没有显示在端口 443 监听的虚拟主机:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 2019-01-14
      相关资源
      最近更新 更多