First time here? Check out the FAQ!
2

Serving from a subdirectory

Okay, I'm making a lot of progress. I want to serve Askbot from mysite.com/ask/, and furthermore, I don't want mysite.com/ being handled by WSGI/Django. As far as I can tell, that means I need to have e.g. WSGIScriptAlias /ask ..., as opposed to WSGIScriptAlias / .... Specifically, when I had ASKBOT_URL = 'ask/' and WSGIScriptAlias / ..., mysite.com/wiki/ was getting handled by Django.

I pretty much have it working how I want, after doing the following:

  • Leave ASKBOT_URL as ''
  • In settings.py, set ASKBOT_MEDIA_URL = 'ask/'
  • In askbot/skins/utils.py, in get_media_url, have it use ASKBOT_MEDIA_URL instead of ASKBOT_URL
  • In the apache config, change the aliases given from e.g. /upfiles/ to /ask/upfiles/

Everything seems to work, except that logging in and logging out takes people to /, not /ask/.

The question: What's the right way to fix this? Am I going about the subdirectory thing all wrong?

Here's the relevant part of my apache config:

#replace with 127.0.0.1 with real IP address
<VirtualHost 123.345.567.789:80>
     ServerAdmin admin@mysite.com
     DocumentURL /opt/webapps/
     ServerName mysite.com

     #aliases to serve static media directly
     #will probably need adjustment
     Alias /ask/m/ /usr/local/lib/python2.6/dist-packages/askbot-0.6.11-py2.6.egg/askbot/skins/
     Alias /ask/upfiles/ /opt/webapps/ask/askbot/upfiles/
     Alias /ask/admin/media/ /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/


     <DirectoryMatch "/opt/webapps/ask/askbot/skins/([^/]+)/media">
        Order deny,allow
        Allow from all
     </DirectoryMatch>
     <Directory "/opt/webapps/ask/askbot/upfiles">
        Order deny,allow
        Allow from all
     </Directory>

     #must be a distinct name within your apache configuration
     WSGIDaemonProcess askbot2
     WSGIProcessGroup askbot2
     WSGIScriptAlias /ask /opt/webapps/ask/django.wsgi
     #make all admin stuff except media go through secure connection
     #<LocationMatch "/admin(?!/media)">
     #    RewriteEngine on
     #    RewriteRule /admin(.*)$ https://example.com/admin$1 [L,R=301]
     #</LocationMatch>
     CustomLog /var/log/apache2/askbot/access_log common
     ErrorLog /var/log/apache2/askbot/error_log
     LogLevel debug

</VirtualHost>
rfrankel's avatar
135
rfrankel
updated 2010-09-23 01:12:59 -0600, asked 2010-09-23 01:11:57 -0600
edit flag offensive 0 remove flag close merge delete

Comments

I should clarify that logging in and out does work, people just get taken to the wrong URL once they've done it.
rfrankel's avatar rfrankel (2010-09-23 01:36:10 -0600) edit
Sorry, it's late and I can't test things right now, but I would leave media url as is and change only ASKBOT_URL. I will try this out tomorrow. The apache Alias is merely a helper that makes static files be served faster. You can take a look into html source and adjust Alias accordingly.
Evgeny's avatar Evgeny (2010-09-23 01:45:15 -0600) edit
No rush. :) Like I said, if I change ASKBOT_URL and make the WSGIScriptAlias for / then all other directories, e.g. /wiki/, get handled by Django. I'm trying to avoid that. The complicated solution is nginx as a reverse proxy...if you can't think of another solution, I'll try that. Thanks!
rfrankel's avatar rfrankel (2010-09-23 01:54:11 -0600) edit
which wiki engine are you using?
Evgeny's avatar Evgeny (2010-09-23 12:29:32 -0600) edit
I was using WikkaWiki, though I may switch to MediaWiki.
rfrankel's avatar rfrankel (2010-09-24 22:17:12 -0600) edit
add a comment see more comments

2 Answers

2

I got this working by using nginx as a front-end proxy. Here's my nginx config:

upstream askbot {
        server  localhost:9000;
}

upstream wiki {
        server  localhost:9001;
}

server {
        listen 80;
        server_name xxxxx.members.linode.com;

        proxy_redirect  off;
        proxy_set_header        Host    $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        location ~ ^/ask {
                access_log      /var/log/nginx/askbot_log;
                root /opt/webapps/ask/;
                proxy_pass  http://askbot;
        }


        location / {
                access_log      /var/log/nginx/wiki_log;
                root /opt/webapps/wiki/;
                rewrite ^/wiki/(.*) /$1;
                proxy_pass  http://wiki;
        }
}

The other thing I had to do was update urls.py:

urlpatterns = patterns('',
    (r'%s' % settings.ASKBOT_URL, include('askbot.urls')),
    (r'^ask/admin/', include(admin.site.urls)),
    #(r'^cache/', include('keyedcache.urls')), - broken views disable for now
    (r'^ask/settings/', include('askbot.deps.livesettings.urls')),
    (r'^ask/robots.txt$', include('robots.urls')),
)

And, as you suggested, I removed the ASKBOT_MEDIA_URL setting.

For completeness, here's my apache config:

<VirtualHost localhost:9000>
     ServerAdmin xxxxxxxxx
     DocumentRoot /opt/webapps/ask/
     ServerName xxxxxxxx

     #aliases to serve static media directly
     #will probably need adjustment
     Alias /ask/m/ /usr/local/lib/python2.6/dist-packages/askbot-0.6.11-py2.6.egg/askbot/skins/
     Alias /ask/upfiles/ /opt/webapps/ask/askbot/upfiles/
     Alias /ask/admin/media/ /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/

     <DirectoryMatch "/opt/webapps/ask/askbot/skins/([^/]+)/media">
        Order deny,allow
        Allow from all
     </DirectoryMatch>
     <Directory "/opt/webapps/ask/askbot/upfiles">
        Order deny,allow
        Allow from all
     </Directory>

     #must be a distinct name within your apache configuration
     WSGIDaemonProcess askbot2
     WSGIProcessGroup askbot2
     WSGIScriptAlias / /opt/webapps/ask/django.wsgi
     #make all admin stuff except media go through secure connection
     #<LocationMatch "/admin(?!/media)">
     #    RewriteEngine on
     #    RewriteRule /admin(.*)$ https://example.com/admin$1 [L,R=301]
     #</LocationMatch>
     CustomLog /var/log/apache2/askbot/access_log common
     ErrorLog /var/log/apache2/askbot/error_log
     LogLevel debug

</VirtualHost>

Thanks again for the support. :)

rfrankel's avatar
135
rfrankel
updated 2010-09-24 23:26:17 -0600, answered 2010-09-24 23:25:12 -0600
edit flag offensive 0 remove flag delete link

Comments

That's neat. Did you measure the advantage you get from using nginx?
Evgeny's avatar Evgeny (2010-09-25 15:25:07 -0600) edit
add a comment see more comments
0

the LOGIN_URL in default settings.py is computed based on ASKBOT_URL. You can change the LOGIN_URL manually.

Alternatively you can add Alias directive to your apache config for the wiki so that wiki is not served by django.

Evgeny's avatar
13.2k
Evgeny
answered 2010-09-23 12:29:12 -0600
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments