forked from junhaoliao/iCtrl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Hosting] prepare for web service hosting
- Loading branch information
1 parent
603e9ba
commit 77358d8
Showing
6 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ | |
**/__pycache__ | ||
**/*.pyc | ||
|
||
/build | ||
/build | ||
|
||
/ictrl.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# iCtrl | ||
|
||
**SSH Remote Desktop Client / Web Service** | ||
|
||
## Config the Flask Application with Apache2 | ||
|
||
### Install and Enable the Apache 2 module 'mod_wsgi' | ||
|
||
``` | ||
sudo apt update | ||
sudo apt install libapache2-mod-wsgi-py3 -y | ||
sudo a2enmod mod-wsgi | ||
``` | ||
|
||
### Apache2 Configuration Example | ||
|
||
To add a config: | ||
|
||
``` | ||
sudo nano /etc/apache2/sites-available/ictrl.conf | ||
``` | ||
|
||
ictrl.conf Content: | ||
|
||
``` | ||
<VirtualHost *:80> | ||
ServerName ictrl.ca | ||
DocumentRoot /var/www/ictrl/client/build | ||
WSGIDaemonProcess ictrl_srv user=ictrl threads=20 | ||
WSGIScriptAlias /api /var/www/ictrl/ictrl_srv.wsgi | ||
<Directory /var/www/ictrl> | ||
WSGIProcessGroup ictrl_srv | ||
WSGIApplicationGroup %{GLOBAL} | ||
Require all granted | ||
</Directory> | ||
LogLevel warn | ||
ErrorLog ${APACHE_LOG_DIR}/ictrl_error.log | ||
CustomLog ${APACHE_LOG_DIR}/ictrl_custom.log combined | ||
</VirtualHost> | ||
``` | ||
|
||
### To Enable the Site Config | ||
|
||
``` | ||
sudo a2ensite ictrl | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
if __name__ == '__main__': | ||
from application import app, APP_HOST, APP_PORT | ||
|
||
if not app.debug: | ||
import os | ||
|
||
from flask import send_from_directory | ||
|
||
|
||
# Reference: https://stackoverflow.com/questions/44209978/serving-a-front-end-created-with-create-react-app-with | ||
# -flask | ||
@app.route('/', defaults={'path': ''}) | ||
@app.route('/<path:path>') | ||
def serve(path): | ||
if path != "" and os.path.exists(os.path.join(app.static_folder, path)): | ||
return send_from_directory(app.static_folder, path) | ||
else: | ||
return send_from_directory(app.static_folder, 'index.html') | ||
|
||
app.run(host=APP_HOST, port=APP_PORT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# activate the virtual environment | ||
activate_this = '/var/www/ictrl/venv/bin/activate_this.py' | ||
with open(activate_this) as file_: | ||
exec(file_.read(), dict(__file__=activate_this)) | ||
|
||
import os | ||
import sys | ||
|
||
# insert the project path so that module 'application' can be found | ||
sys.path.insert(0, '/var/www/ictrl/') | ||
|
||
# read the config file | ||
# as we don't want to hard-code those sensitive data and commit them into Git | ||
with open('ictrl.conf', 'r') as config_file: | ||
for line in config_file: | ||
if line.startswith('#'): | ||
continue | ||
|
||
try: | ||
name, value = line.strip().split('=') | ||
os.environ[name] = value | ||
except ValueError: | ||
pass | ||
|
||
# now import the application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
wheel | ||
bcrypt | ||
flask | ||
Flask-SQLAlchemy | ||
paramiko | ||
Pillow | ||
psycopg2-binary | ||
|