librelist archives

« back to archive

flask-login and Apache VirtualHost errors

flask-login and Apache VirtualHost errors

From:
joe meiring
Date:
2013-01-02 @ 20:10
Hi All,


I have a flask application that requires login authentication using
flask-login to do the session handling. The application is using
VirtualHost in apache, and the root url is /myapp for instance. When I hit
a URL that requires login (for instance /myapp/admin), I get the desired
login form and page, but then it redirects to /login instead of
/myapp/login and
I get a 404 error URL not found.

If I host the application at / instead of /myapp in the apache
configuration, everything works as expected. Is there a setting for
flask-login that would fix this, or another workaround?

My settings and login view are as follows:


login_manager.login_view = "login"

@app.route("/login", methods=['GET', 'POST'])def login():
    form = LoginForm()
    if form.validate():
       #do login stuff
    else:
        flash("Bad username and/or password!")
        return render_template("login.html", form=form)

And here is the VirtualHost directive for apache:

<VirtualHost *:80>
    #ServerAdmin webmaster@mydomain
    WSGIScriptReloading On
    WSGIScriptAlias /myapp /envs/myApp/myapp/myapp.wsgi
    WSGIDaemonProcess myapp threads=5 user=user1 group=user1
    <Directory "/envs/MyApp/myapp/">
            WSGIProcessGroup image_search
            WSGIApplicationGroup %{GLOBAL}
            Order allow,deny
            Allow from all
    </Directory></VirtualHost>

Thanks!

Re: [flask] flask-login and Apache VirtualHost errors

From:
Richard Lacap
Date:
2013-01-03 @ 15:11
Could you use an Apache RewriteCond + Rule to prepend /Myapp/{requested
uri} for requests that match that http host name?


On Wed, Jan 2, 2013 at 2:10 PM, joe meiring <josephmeiring@gmail.com> wrote:

> Hi All,
>
>
> I have a flask application that requires login authentication using
> flask-login to do the session handling. The application is using
> VirtualHost in apache, and the root url is /myapp for instance. When I
> hit a URL that requires login (for instance /myapp/admin), I get the
> desired login form and page, but then it redirects to /login instead of
> /myapp/login and I get a 404 error URL not found.
>
> If I host the application at / instead of /myapp in the apache
> configuration, everything works as expected. Is there a setting for
> flask-login that would fix this, or another workaround?
>
> My settings and login view are as follows:
>
>
> login_manager.login_view = "login"
>
> @app.route("/login", methods=['GET', 'POST'])def login():
>     form = LoginForm()
>     if form.validate():
>        #do login stuff
>     else:
>         flash("Bad username and/or password!")
>         return render_template("login.html", form=form)
>
>  And here is the VirtualHost directive for apache:
>
> <VirtualHost *:80>
>     #ServerAdmin webmaster@mydomain
>     WSGIScriptReloading On
>     WSGIScriptAlias /myapp /envs/myApp/myapp/myapp.wsgi
>     WSGIDaemonProcess myapp threads=5 user=user1 group=user1
>     <Directory "/envs/MyApp/myapp/">
>             WSGIProcessGroup image_search
>             WSGIApplicationGroup %{GLOBAL}
>             Order allow,deny
>             Allow from all
>     </Directory></VirtualHost>
>
> Thanks!
>
>

Re: [flask] flask-login and Apache VirtualHost errors

From:
joe meiring
Date:
2013-01-03 @ 16:57
I think that would work, but would rather stay away from apache
configurations if possible. Is there some flask setting identifying the
root of the URL for the application? It looks like flask-login is doing a
url_for() for the login view that is defined in the application by the
login_manager.login_view setting. Flask is just returning /login from that
function call.

Unfortunately, I can't use blueprints as the other applications on this
server have conflicting package requirements. I think that would work
otherwise.




On Thu, Jan 3, 2013 at 9:11 AM, Richard Lacap <richardlacap@gmail.com>wrote:

> Could you use an Apache RewriteCond + Rule to prepend /Myapp/{requested
> uri} for requests that match that http host name?
>
>
> On Wed, Jan 2, 2013 at 2:10 PM, joe meiring <josephmeiring@gmail.com>wrote:
>
>> Hi All,
>>
>>
>> I have a flask application that requires login authentication using
>> flask-login to do the session handling. The application is using
>> VirtualHost in apache, and the root url is /myapp for instance. When I
>> hit a URL that requires login (for instance /myapp/admin), I get the
>> desired login form and page, but then it redirects to /login instead of
>> /myapp/login and I get a 404 error URL not found.
>>
>> If I host the application at / instead of /myapp in the apache
>> configuration, everything works as expected. Is there a setting for
>> flask-login that would fix this, or another workaround?
>>
>> My settings and login view are as follows:
>>
>>
>> login_manager.login_view = "login"
>>
>> @app.route("/login", methods=['GET', 'POST'])def login():
>>     form = LoginForm()
>>     if form.validate():
>>        #do login stuff
>>     else:
>>         flash("Bad username and/or password!")
>>         return render_template("login.html", form=form)
>>
>>  And here is the VirtualHost directive for apache:
>>
>> <VirtualHost *:80>
>>     #ServerAdmin webmaster@mydomain
>>     WSGIScriptReloading On
>>     WSGIScriptAlias /myapp /envs/myApp/myapp/myapp.wsgi
>>     WSGIDaemonProcess myapp threads=5 user=user1 group=user1
>>     <Directory "/envs/MyApp/myapp/">
>>             WSGIProcessGroup image_search
>>             WSGIApplicationGroup %{GLOBAL}
>>             Order allow,deny
>>             Allow from all
>>     </Directory></VirtualHost>
>>
>> Thanks!
>>
>>
>

Re: [flask] flask-login and Apache VirtualHost errors

From:
Richard Lacap
Date:
2013-01-03 @ 17:40
I am not aware of any config options setting a doc root. Though (again
going back to apache) you might want to try defining the document root for
the virtual host.
e.g.: DocumentRoot /myapp

see http://httpd.apache.org/docs/2.2/vhosts/examples.html



On Thu, Jan 3, 2013 at 10:57 AM, joe meiring <josephmeiring@gmail.com>wrote:

> I think that would work, but would rather stay away from apache
> configurations if possible. Is there some flask setting identifying the
> root of the URL for the application? It looks like flask-login is doing a
> url_for() for the login view that is defined in the application by the
> login_manager.login_view setting. Flask is just returning /login from that
> function call.
>
> Unfortunately, I can't use blueprints as the other applications on this
> server have conflicting package requirements. I think that would work
> otherwise.
>
>
>
>
> On Thu, Jan 3, 2013 at 9:11 AM, Richard Lacap <richardlacap@gmail.com>wrote:
>
>> Could you use an Apache RewriteCond + Rule to prepend /Myapp/{requested
>> uri} for requests that match that http host name?
>>
>>
>> On Wed, Jan 2, 2013 at 2:10 PM, joe meiring <josephmeiring@gmail.com>wrote:
>>
>>> Hi All,
>>>
>>>
>>> I have a flask application that requires login authentication using
>>> flask-login to do the session handling. The application is using
>>> VirtualHost in apache, and the root url is /myapp for instance. When I
>>> hit a URL that requires login (for instance /myapp/admin), I get the
>>> desired login form and page, but then it redirects to /login instead of
>>> /myapp/login and I get a 404 error URL not found.
>>>
>>> If I host the application at / instead of /myapp in the apache
>>> configuration, everything works as expected. Is there a setting for
>>> flask-login that would fix this, or another workaround?
>>>
>>> My settings and login view are as follows:
>>>
>>>
>>> login_manager.login_view = "login"
>>>
>>> @app.route("/login", methods=['GET', 'POST'])def login():
>>>     form = LoginForm()
>>>     if form.validate():
>>>        #do login stuff
>>>     else:
>>>         flash("Bad username and/or password!")
>>>         return render_template("login.html", form=form)
>>>
>>>  And here is the VirtualHost directive for apache:
>>>
>>> <VirtualHost *:80>
>>>     #ServerAdmin webmaster@mydomain
>>>     WSGIScriptReloading On
>>>     WSGIScriptAlias /myapp /envs/myApp/myapp/myapp.wsgi
>>>     WSGIDaemonProcess myapp threads=5 user=user1 group=user1
>>>     <Directory "/envs/MyApp/myapp/">
>>>             WSGIProcessGroup image_search
>>>             WSGIApplicationGroup %{GLOBAL}
>>>             Order allow,deny
>>>             Allow from all
>>>     </Directory></VirtualHost>
>>>
>>> Thanks!
>>>
>>>
>>
>