Posts Tagged ‘apache’

How to run a Flask application in a subpath, using Apache mod_proxy

Although there are much better solutions for running wsgi applications (mod_wsgi for Apache or uwsgi, gunicorn for nginx), I’ve been cracking my head trying to set it up using mod_proxy and in a subpath.

What I wanted to achieve is:

http://ex.com/appname/ <-> http://localhost:5000/
http://ex.com/appname/redir -> http://ex.com/appname/destination

(because http://localhost:5000/redir -> http://localhost:5000/destination)

Said and done, having an instance of the app running on :5000, most of the pages on the internet suggest the next apache configuration (including the mod_proxy official docs):

ProxyPass /appname/  http://localhost:5000/
ProxyPassReverse /appname/ http://localhost:5000/

Wrong! The correct setup, for a domain ex.com, is:

ProxyPass /appname/ http://localhost:5000/
ProxyPassReverse /appname/ http://ex.com/

The explanation stays in the ProxyPassReverse reference: it will will do a string replace in the HTTP Location headers. Our app redirects to ex.com, which translates to /appname/ (because of ProxyPassReverse), which translates to our localhost:5000 server (because of ProxyPass).

Please correct me if I’m wrong, but this was the only setup proved to be working.




Cum activezi mod_rewrite in apache2 pe Ubuntu 7.04

Modulul mod_rewrite al serverului Apache este responsabil de url-urile frumoase. Astfel, in loc de:

http://www.siteulmeu.ro/index.php?q=pages&page=Contact

utilizatorul poate “vedea” in browser:

http://www.siteulmeu.ro/pages/Contact

Pe scurt, m-am lovit de problema activarii acestui modul, si, desi solutia este simpla, am avut un pic de sapat dupa ea. Solutia se aplica la serverul apache2 pe distributia Ubuntu.

Deci, ce trebuie facut:

$ sudo a2enmod rewrite

apoi:

$ cd /etc/apache2/sites-available/$ sudo gedit default

se face modificarea liniei AllowOverride din None in all:

<directory>
Options IndexesFollowSymLinks
MultiViewsAllowOverride all
Order allow, deny
allow from all
</directory>

( /var/www putea fi alt folder, folderul root pentru apache, de exemplu la mine este /home/alex/htdocs )
si in final:

$ sudo /etc/init.d/apache2 restart

Asta e tot, mai departe tot ceea ce trebuie facut este sa completezi folderele care te intereseaza cu fisiere .htaccess corespunzatoare (de exemplu /var/www/.htaccess). Un exemplu de continut foarte simplu al fisierului .htaccess este:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z\/0-9\ ]*)$  index.php?url=$1

Legaturi: http://www.gtrev.it/ubuntu-edgy-modrewrite-e-drupal
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html