Item 1

From WeBWorK_wiki
Jump to navigation Jump to search

Implement Option B (NGINX)

You can implement Option B at any time and your active courses will continue to function seemingly without change. The only change behind the scenes will be that static images, pages and MathJax (if you installed it locally) will be served by a light weight web server.

Install and Configure NGINX

First we install the light weight webserver NGINX

Run the command

$ sudo apt install nginx
[sudo] password for wwadmin: <wwadmin password>

Now we configure NGINX. First let's make a backup of the configuration file.

$ cd /etc/nginx/sites-available/
$ sudo cp default default.bak1
[sudo] password for wwadmin: <wwadmin password>

Now edit the default file.

$ sudo nano default


Apache2 is listening on port 80 so we need an alternate port for NGINX to listen to. Standard alternate ports for this are usually 81, 8000, or 8080. 8080 is the only port that is listed as an official alternate at http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers . Note that in rare cases an institution may block httpd requests to port 8080. If any of your students report that they can not see graphics, they will have to request that access to requests to port 8080 be allowed.

Find the lines

server {
       listen 80 default_server;
       listen [::]:80 default_server;

and replace them by

server {
       listen 8080 default_server;
       listen [::]:8080 default_server;

Now we make a few more changed that allow MathJax to run under NGINX. You can skip these if you are running MathJax remotely. Under the lines you just edited, add the line

       add_header Access-Control-Allow-Origin *;

Then under the lines

location / {
               # First attempt to serve request as file, then
               # as directory, then fall back to displaying a 404.
               try_files $uri $uri/ =404;
       }

add the lines

       location /webwork2_files {
               alias /opt/webwork/webwork2/htdocs/;
       }

Then save the file and quit.

Now reboot your server and check that nginx is running

sudo systemctl status nginx

Test NGINX

First run the command

 $ sudo lsof -i -P -n | grep LISTEN

and check that NGINX is listening on port 8080

Now test your server by connecting to your server from a browser on a remote machine ("http://yourserver.yourschool.edu:8080/"). You should see the Apache2 Ubuntu Default Page but without a graphic for the Ubuntu Logo indicating that NGINX is running.

Configure WeBWorK to Take Advantage of NGINX

First let's make a backup copy of localOverrides.conf so that we can easily back out of these changes if necessary.

$ cd /opt/webwork/webwork2/conf
$ cp localOverrides.conf localOverrides.conf.bak2


Now edit localOverrides.conf. Be sure toles replace yourserver.yourschool.edu with the correct address.

$ nano localOverrides.conf

Above the lines

################################################################################
# Directory for temporary files
################################################################################

add the lines (before you just copy and paste remember to change "yourserver.yourschool.edu")

################################################################################
# URLs to access temporary files and MathJax using NGINX
################################################################################
$webworkURLs{htdocs_temp}   = 'http://yourserver.yourschool.edu:8080/webwork2_files/tmp';
$webworkURLs{equationCache} = 'http://yourserver.yourschool.edu:8080/webwork2_files/tmp/equations';
$courseURLs{html_temp}      = "http://yourserver.yourschool.edu:8080/webwork2_files/tmp/$courseName";

Then save the file and quit. Now restart apache and NGINX.

$ sudo apache2ctl graceful
password:<wwadmin password>
$ sudo systemctl restart nginx


If you installed MathJax locally under the above line add the lines

# Location of MathJax script, used for the MathJax display mode.
$webworkURLs{MathJax}       = 'http://yourserver.yourschool.edu:8080/webwork2_files/mathjax/es5/tex-chtml.js';

If you are running MathJax remotely, don't add the above lines.

Then save the file and quit.

Now restart apache and lighttp.

$ sudo apache2ctl graceful
password:<wwadmin password>
$ sudo systemctl restart lighttpd

Test that Everything is Working Properly

To test things go to your test course http://yourserver.yourschool.edu/webwork2/myTestCourse/. Log into your course and view a problem with a graphic image (e.g. Problem 2 of the Demo set. Since you have Admin or Prof privileges, you can view sets which are not yet open). Right click on the image and click on Properties (or whatever is appropriate on your browser, e.g. copy image location) and check that the image is being served from port 8080 (something like http://yourserver.yourschool.edu:8080/webwork2_files/tmp/myTestCourse/images/...).

If MathJax is installed locally, to test that MathJax is using NGINX, view a problem with some typeset equations. Right click on the equation and you should see the MathJax menu which confirms MathJax is being used. Next look at the source code for the page (e.g. right click on most browsers and select "View page source") and in the source, search for tex-chtml.js. You should see that this is being loaded from port 8080. Obviously, if you are running MathJax remotely, you will see it is being loaded from the CDN.

Disabling Option B (lighttpd) for a single course

If your server is hosting courses from different institutions, you may find that you need to disable using lighttpd for a single course, e.g. because the institution blocks access to port 8080. Actually since port 8080 is an "official" alternate httpd port, you should first try to get the network administrators at the institution to grant access to port 8080. Failing this, you can disable using lighttpd and instead use apache for a single course by adding the following lines to the end of the course's course.conf file which is located in the top level directory for the course (usually /opt/webwork/courses/course_name). Note that using apache instead of lighttpd will put a slightly larger load on the server. Also note that you need "admin" level privileges to edit the course.conf file. Instructors with only "professor" level privileges can not do this from within WeBWorK. If you are running MathJax remotely, don't add the last line.

# Do not use lightppd (port 8080) for this course
$webworkURLs{htdocs_temp}   = '/wwtmp';
$courseURLs{html_temp}   = "/wwtmp/$courseName";
$webworkURLs{equationCache} = "$webworkURLs{htdocs_temp}/equations";
$webworkURLs{MathJax}       = "$webworkURLs{htdocs}/mathjax/es5/tex-chtml.js";

I repeat if you are running MathJax remotely, don't add the last line above.