# Item 1

### Implement Option B (NGINX)

As is the case for Option A 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

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;
}

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. Note that while Option B is independent of Option A, we assume most people implementing Option B will have already implemented Option A. Therefore we give instructions for editing localOverrides.conf assuming that Option A has been implemented. If this is not the case, modify the instructions below accordingly. Also replace yourserver.yourschool.edu with the correct address.$ nano localOverrides.conf

Find the line

$webworkURLs{htdocs_temp} = '/wwtmp' and replace it by #$webworkURLs{htdocs_temp}   = '/wwtmp';
$webworkURLs{htdocs_temp} = 'http://yourserver.yourschool.edu:8080/wwtmp'; Find the line$courseURLs{html_temp}   = "/wwtmp/$courseName"; and replace it by #$courseURLs{html_temp}   = "/wwtmp/$courseName";$courseURLs{html_temp}   = "http://yourserver.yourschool.edu:8080/wwtmp/$courseName"; 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/wwtmp/myTestCourse/images/...).

If MathJax is installed locally, to test that MathJax is using lighttpd, 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

$webworkURLs{htdocs_temp} = '/wwtmp';$courseURLs{html_temp}   = "/wwtmp/$courseName";$webworkURLs{equationCache} = "$webworkURLs{htdocs_temp}/equations";$webworkURLs{MathJax}       = "\$webworkURLs{htdocs}/mathjax/es5/tex-chtml.js";