Environment:
Python 3.7.5
Flask 1.1.2
Hosting company: Ionos
Type: VPS on ubuntu with Plesk panel.
Ubuntu 18.04.5 LTS, Codename: bionic
I have a website domain.com. I need a dashboard on a subdomain "dashboard.domain.com" for example.
My server is a virtual server using "virtual hosts" with apache for all my domain names located on this VPS.
I am trying to deploy my python flask application on my ubuntu server with a subdomain.
I installed the necessary packages on my server (wsgi, flask, etc…)
After that, this is what I’ve done:
-
I created a subdomain "dashboard.domain.com"
-
The files of domain.com are located there :
/var/www/vhosts/domain.com/httpdocs/
I created a folder "dashboard" in domain.com folder :
/var/www/vhosts/domain.com/dashboard
In this folder I upload all the files of my Flask app:
dashboard/
- forms.py
-__init__.py
-models.py
-myproj
-routes.py
-static/
-templates/
dashboard.wgsi
favicon.ico
-
I created the dashboard.wgsi file:
#!/usr/bin/python
import sys
import logging
sys.stdout = sys.stderr
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/vhosts/domain.com/dashboard/")from dashboard import app as application
application.secret_key = ‘Paris@TOTO’
and init.py file:
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@[email protected]/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)
-
I created the conf file "dashboard.conf" in /etc/apache2/sites-available/
<VirtualHost *:80>
ServerAdmin [email protected] 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
-
I enable this new virtual host in /etc/apache2/:
sudo a2ensite dashboard
-
I restarted Apache:
sudo service apache2 restart
Then, when I test the url ‘dashboard.domain.com" in my browser I get ERR_CONNECTION_REFUSED error.
So I went to check the error log files in /var/log/apache2
access-dashboard.log
access.log
error-dashboard.log
error.log
etc...
access.log, access-dashboard.log and error-dashboard.log are empty!
But error.log shows:
[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'
Does anyone can help me to fix this issue please?
2
Answers
You have a redirect to https:/… but you dont show a virtual host listening at port 443:
This indicates an error with your SSL settings for Apache, it’s an easy one to tackle, according to this article
You should rename your server to localhost, such as:
I’d like to add that I haven’t been able to reproduce your error, all I get are warnings but my app seems to be up and running fine. My goal with this answer is not only to help but also to verify that this issue can be solved this way.
Please come back and tell us how it went ))