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>

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
rfrankel's avatar
135
rfrankel
updated 14 years ago, asked 14 years ago

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 (14 years ago)
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 (14 years ago)
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 (14 years ago)
which wiki engine are you using?
Evgeny's avatar Evgeny (14 years ago)
I was using WikkaWiki, though I may switch to MediaWiki.
rfrankel's avatar rfrankel (14 years ago)
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. :)

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
rfrankel's avatar
135
rfrankel
updated 14 years ago, answered 14 years ago
link

Comments

That's neat. Did you measure the advantage you get from using nginx?
Evgeny's avatar Evgeny (14 years ago)
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.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 14 years ago
link

Comments

see more comments