Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

JATOS server and static folder on Apache2

Hello,

I am using JATOS with jspsych running on a server using Apache2. I used the configuration file as described on the JATOS website.

My problem is that I have a whole series of components that get executed/served. For each component many of the same files are downloaded. For instance, jspsych.js, jspsych.css, etc.

I am looking for ways to cache these files. I see since JATOS creates unique URLs each time, so that caching is not possible. So the idea is to create a static folder to put the jspsych code and then import it into my html components. We (actually my local IT genius) have been working with the apache2 CONF file and have had no luck getting this work. We have added things like the following to the conf file:

DocumentRoot /var/www/html

 Alias /static /var/www/html

My goal is to speed things up as much as possible. Can anyone provide some guidance, please?

Thank you,

Jason

Comments

  • Hi Jason,

    I see since JATOS creates unique URLs each time, so that caching is not possible.

    That is correct. But JATOS additionally to the file serving does some authorization. Only participants currently running a study are allowed to access the files in the study assets folder. If you have some files there that not everyone should be able do access, e.g. trial data, this is what you want. On the other side if you have just 'normal' files, like images or videos, there is no reason to not put them somewhere else, e.g. in some folder where Apache can do the delivery faster.

    We (actually my local IT genius) have been working with the apache2 CONF file and have had no luck getting this work.

    I tried a bit to get this work but failed too. I'm not much of an Apache expert, I guess. It shouldn't be too difficult though, one part of the requests get delivered by Apache as static files and the other part get proxied to port localhost:9000 where JATOS lives. My config looks something like this, but somehow the static files do not get delivered.

    <VirtualHost *:80>
      ServerName example.com
      ServerAlias www.example.com
    
      Alias /static/ /var/www/html/
      <Directory /var/www/html/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
      </Directory>
    
      ProxyPass /static/ !
    
      # JATOS uses WebSockets for its batch and group channels
      RewriteEngine On
      RewriteCond %{HTTP:Upgrade} =websocket [NC]
      RewriteRule /(.*)           ws://localhost:9000/$1 [P,L,UnsafeAllow3F]
      RewriteCond %{HTTP:Upgrade} !=websocket [NC]
      RewriteRule /(.*)           http://localhost:9000/$1 [P,L,UnsafeAllow3F]
    
      # Proxy everything to the JATOS running on localhost on port 9000
      ProxyPass / http://localhost:9000/
      ProxyPassReverse / http://localhost:9000/
    </VirtualHost>
    

    Please tell me when you figured it out. I'm curious!

    Best,

    Kristian

  • Hello Kristian,

    Sorry for the delay, but Jarno (my local IT genius) figured it out.

    We made the following folder where I put my unchanging files that can be cached: /var/www/html/static/

    I will put most of the jspsych Javascript code that I use in there.

    For each file I want loaded (and cached) I make the following change within my HTML files. (In this example I just copied my entire jspsych folder into the static folder).

    <script src="jspsych/dist/jspsych.js"></script>
    

    to

    <script src="/static/jspsych/dist/jspsych.js"></script>
    


    NOTE: when you are testing this to make sure it works and using the Chrome developer tools, make sure you do NOT have the "Disable cache" button checked.


    The following is my conf file

    <MDomain mydomain.ca>
      MDCertificateAgreement accepted
    </MDomain>
    
    
    <VirtualHost *:80>
      ServerName mydomain.ca
      ServerAdmin my@email.ca
      # Redirect all unencrypted traffic to the respective HTTPS page
      Redirect "/" "https://mydomain.ca"
    
    
    </VirtualHost>
    
    
    <VirtualHost *:443>
      ServerName mydomain.ca
      ServerAdmin my@email.ca
      # Restrict access to JATOS GUI to local network
      #<Location "/jatos">
      #  Order deny,allow
      #  Deny from all
      #  Allow from 127.0.0.1 ::1
      #  Allow from localhost
      #  Allow from 192.168
      #</Location>
    
    
      # Your certificate for encryption
      SSLEngine On
    
    
    ProxyPass /static !
    Alias /static /var/www/html/static
    
    
      # JATOS uses WebSockets for its batch and group channels
      RewriteEngine On
      RewriteCond %{HTTP:Upgrade} =websocket [NC]
      RewriteRule /(.*)           ws://localhost:9000/$1 [P,L,UnsafeAllow3F]
      
      RewriteCond %{REQUEST_URI} !^/static.*
      RewriteCond %{HTTP:Upgrade} !=websocket [NC]
      RewriteRule /(.*)           http://localhost:9000/$1 [P,L,UnsafeAllow3F]
    
    
     # Proxy everything to the JATOS running on localhost on port 9000
     #  DocumentRoot /var/www/html
    	ProxyPass / http://localhost:9000/
            ProxyPassReverse / http://localhost:9000/
    </VirtualHost>
    
    
    


    I hope this helps,

    Jason

  • krikri
    edited June 24

    Hi Jason,

    I was missing the RewriteCond for the static folder! And the ProxyPass and ProxyPassReverse isn't necessary since we use the RewriteCond.

    Just for local development, if someone else is interested and for my own reference, I add an Apache config for port 80 without encryption. I put it under /etc/apache2/sites-available/example.com.conf.

    ServerName www.example.com
    
    <VirtualHost *:80>  
      RewriteEngine On
    
      # JATOS uses WebSockets for its batch and group channels
      RewriteCond %{HTTP:Upgrade} =websocket [NC]
      RewriteRule /(.*)           ws://localhost:9000/$1 [P,L]
    
      # Rewrite condition for static files
      RewriteCond %{REQUEST_URI}  !^/static.*
      # Rewrite condition for everything else
      RewriteCond %{HTTP:Upgrade} !=websocket [NC]
      RewriteRule /(.*)           http://localhost:9000/$1 [P,L]
    </VirtualHost>
    

    Thanks for posting this here. I'll update JATOS docs.

    Best,

    Kristian

    EDIT: See Apache Docs

Sign In or Register to comment.