This is an old revision of the document!
Using nginx to serve static content
Warning: While this seems to work well for the dynamic catalogue, there are known problems using a reverse proxy (such as nginx) with the basic catalogue/SlimPAC/SuperCat. Work needs to be done to prevent hostname/port from being set incorrectly for generated links in these pages.
A default Evergreen install uses Apache to serve up both static and dynamic content. This causes Apache to have to constantly respawn backend processes. Using a high-performance proxy server to serve up static content and pass on the dynamic requests to Apache can make you, your server, and your users happier. The following document is based on a full handful of late-night hours trying out nginx for the first time, so use at your own risk…
Steps to get this working on Ubuntu Karmic, assuming that nginx and Apache are running on the same server:
- Install nginx: sudo aptitude install nginx
- Copy the configuration file (below) into a file called /etc/nginx/sites-available/evergreen and create a symbolic link to the file at /etc/nginx/sites-enabled/evergreen
- Modify the nginx configuration file server_name directive to match all the names of your virtual hosts
- Modify /etc/apache2/ports.conf to change port 80 to 9080 and port 443 to 9443.
- Modify /etc/apache2/eg_vhost.conf to change the "Listen 443" directive to "Listen 9443"
- Restart nginx and Apache to put the new configuration in place
- Enjoy!
server { listen 80; server_name test.concat.ca js-test.concat.ca css-test.concat.ca images-test.concat.ca; root /openils/var/web; access_log /var/log/nginx/evergreen.access.log; error_log /var/log/nginx/evergreen.error.log; location /js/ {} location ~* \.(css|gif|jpg|jpeg|js|png)$ { rewrite "^(/opac/)([a-z]{2}-[A-Z]{2}/)(.*\.)(css|gif|jpg|jpeg|js|png)$" $1$3$4 break; } location / { rewrite ^(/?)$ /opac/en-US/skin/default/xml/index.xml redirect; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://localhost:9080; proxy_redirect off; port_in_redirect off; if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") { expires 31d; break; } } # Enable compression of content gzip on; # IE 6 doesn't deal well with gzipped pages gzip_disable "MSIE [1-6]\."; # Compress proxied content as well - enables XML / XUL files # to be compressed after XMLENT has had its way with them gzip_proxied any; # By default, nginx only compresses text/html gzip_types text/html text/plain text/xml text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; # Ensure that large content (the most important stuff) can be compressed gzip_buffers 16 8k; } server { listen 443; server_name test.concat.ca js-test.concat.ca css-test.concat.ca images-test.concat.ca; root /openils/var/web; ssl on; ssl_certificate /etc/apache2/ssl/*.concat.ca.crt; ssl_certificate_key /etc/apache2/ssl/*.concat.ca.key; access_log /var/log/nginx/evergreen_ssl.access.log; error_log /var/log/nginx/evergreen_ssl.error.log; location /js/ {} location ~* \.(css|gif|jpg|jpeg|js|png)$ { rewrite "^(/opac/)([a-z]{2}-[A-Z]{2}/)(.*\.)(css|gif|jpg|jpeg|js|png)$" $1$3$4 break; } location / { rewrite ^(/?)$ /opac/en-US/skin/default/xml/index.xml redirect; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass https://localhost:9443; proxy_redirect off; port_in_redirect off; if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") { expires 31d; break; } } # Enable compression of content gzip on; # IE 6 doesn't deal well with gzipped pages gzip_disable "MSIE [1-6]\."; # Compress proxied content as well - enables XML / XUL files # to be compressed after XMLENT has had its way with them gzip_proxied any; # By default, nginx only compresses text/html gzip_types text/html text/plain text/xml text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; # Ensure that large content (the most important stuff) can be compressed gzip_buffers 16 8k; }