Skip to content
Snippets Groups Projects
Commit d051490f authored by David Sveningsson's avatar David Sveningsson
Browse files

running flask behind nginx

parent 0d6242c4
Branches
No related tags found
No related merge requests found
__pycache__/
*.py[cod]
/.vagrant
......@@ -13,6 +13,7 @@ Vagrant.configure("2") do |config|
# connect to netlimiter interface acting as a router forwarding
# all traffic out back to the regular host network
router.vm.network "public_network", ip: "10.13.0.1", bridge: "netlim"
router.vm.network "forwarded_port", guest: 80, host: 3080
# provisioning
router.vm.provision "ansible_local" do |ansible|
......
- name: restart nginx
service: name=nginx state=reloaded
- name: restart supervisor
service: name=supervisor state=restarted
- name: Installing dependencies
apt:
state: present
update_cache: yes
cache_valid_time: 86400
name:
- nginx
- python3-flask
- supervisor
- name: Configure nginx
notify: restart nginx
template:
src: nginx.conf
dest: /etc/nginx/sites-enabled/default
- name: Configure flask supervisor
notify: restart supervisor
template:
src: netlimiter.conf
dest: /etc/supervisor/conf.d/netlimiter.conf
[program:flask]
command=python3 run.py --debug
startsecs=5
user=vagrant
redirect_stderr=true
directory=/vagrant
stdout_logfile=/var/log/netlimiter.log
startretries=60
server {
listen 80 default_server;
server_name _;
root /vagrant/public;
location = / {
try_files /index.html =404;
}
location / {
try_files $uri =404;
}
location /api {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:5000 ;
}
}
......@@ -8,6 +8,7 @@
roles:
- router
- netlimiter
tasks:
- name: Installing misc utils
......@@ -15,3 +16,4 @@
state: present
name:
- tcpdump
- curl
#pylint: disable=wrong-import-position
from flask import Flask
app = Flask(__name__)
import netlimiter.api
import flask
from netlimiter import app
@app.route("/api/foo")
def hello():
return flask.jsonify({'foo': True})
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Netlimiter</title>
</head>
<body>
<h1>Netlimiter</h1>
</body>
</html>
[MESSAGES CONTROL]
disable=invalid-name,missing-docstring
run.py 0 → 100644
import argparse
from netlimiter import app
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true')
args = parser.parse_args()
app.run(**vars(args))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment