Diferencia entre revisiones de «Usuario:Lmorillas/desarrollo web servidor/flask/despliegue»

De WikiEducator
Saltar a: navegación, buscar
Línea 106: Línea 106:
 
</source>
 
</source>
  
 +
==== login por https ====
 +
<source lang="python">
 +
@app.route('/login', methods=['GET', 'POST'])
 +
def login():
 +
    if not request.is_secure:
 +
        return redirect(request.url.replace("http://", "https://"))
 +
    error = None
 +
    if request.method == 'POST':
 +
        if request.form['username'] != app.config['USERNAME']:
 +
            error = 'Invalid username'
 +
        elif request.form['password'] != app.config['PASSWORD']:
 +
            error = 'Invalid password'
 +
        else:
 +
            session['logged_in'] = True
 +
            flash('You were logged in')
 +
            url = url_for('show_entries')
 +
            return redirect(urlparse.urljoin(request.url.replace("https://", "http://"), url))
 +
</source>
  
  

Revisión de 11:31 12 dic 2013


Apache con WSGI

Documentación


Pasos

Icon objectives.jpg

Pasos


Instalar mod-wsgi

$ sudo apt-get update
$ sudo apt-get install libapache2-mod-wsgi

Configurar usuario

 $ useradd -M flask
 $ usermod -s /bin/false flask
 $ usermod -L flask
 $ adduser flask www-data

lanzador.wsgi

# Si usamos virtualenv
activate_this = '/ruta/al/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
 
# Si no está instalada la app: para poder importar
import sys
sys.path.insert(0, '/ruta/a/la/aplicacion')
 
from <miaplicacion> import app as application
Tiene que tener permisos de ejecución
 $ chmod +x lanzador.wsgi

virtual host en apache

<VirtualHost *:80>
    ServerName example.com
 
    WSGIDaemonProcess yourapplication user=user1 group=group1 threads=5 home=/var/wwww/home ...
    WSGIScriptAlias / /var/www/yourapplication/lanzador.wsgi
 
    <Directory /var/www/yourapplication>
        WSGIProcessGroup yourapplication
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>
 $ sudo a2ensite nuevo_sitio
 $ sudo service apache2 restart | reload

Si hay errores ...

 $ tail -f /var/log/apache/error.log


con userdir

<Directory /home/*/public_html>
	Options Indexes FollowSymLinks MultiViews ExecCGI
	AddHandler wsgi-script .wsgi
	Order allow,deny
	Allow from all
</Directory>


https ??

 $ sudo a2enmod ssl
<VirtualHost *:443>
    ServerName flaskr
 
    WSGIScriptAlias / /home/lm/tmp/flaskr/flaskr.wsgi
 
    SSLEngine On
    SSLCertificateFile /home/lm/tmp/flaskr/crt/server.crt
    SSLCertificateKeyFile /home/lm/tmp/flaskr/crt/server.key
    #SSLCertificateChainFile /path/to/sub.class1.server.ca.pem
 
    <Directory /home/lm/tmp/flaskr>
        WSGIProcessGroup flaskr
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        #Order deny,allow
        #Allow from all
        Require all granted
    </Directory>
</VirtualHost>

login por https

@app.route('/login', methods=['GET', 'POST'])
def login():
    if not request.is_secure:
        return redirect(request.url.replace("http://", "https://"))
    error = None
    if request.method == 'POST':
        if request.form['username'] != app.config['USERNAME']:
            error = 'Invalid username'
        elif request.form['password'] != app.config['PASSWORD']:
            error = 'Invalid password'
        else:
            session['logged_in'] = True
            flash('You were logged in')
            url = url_for('show_entries')
            return redirect(urlparse.urljoin(request.url.replace("https://", "http://"), url))


Despliegue en Heroku