Skip to content

Commit

Permalink
Merge pull request #10151 from internetarchive/fix-nginx-logs
Browse files Browse the repository at this point in the history
Switch to using NJS for nginx IP anonymization
  • Loading branch information
mekarpeles authored Jan 15, 2025
2 parents 9840d58 + 9387074 commit 0045f02
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
18 changes: 3 additions & 15 deletions docker/Dockerfile.olbase
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,10 @@ RUN apt-get -qq update && apt-get install -y \
COPY scripts/install_nodejs.sh ./
RUN ./install_nodejs.sh && rm ./install_nodejs.sh

# Install Archive.org nginx w/ IP anonymization
# Install nginx
USER root
RUN apt-get update && apt-get install -y --no-install-recommends nginx curl letsencrypt \
# nginx-plus
apt-transport-https lsb-release ca-certificates wget \
# log rotation service for ol-nginx
logrotate \
# rsync service for pulling monthly sitemaps from ol-home0 to ol-www0
rsync
COPY scripts/install_openresty.sh ./
RUN ./install_openresty.sh && rm ./install_openresty.sh
RUN rm /usr/sbin/nginx
RUN curl -L https://archive.org/download/nginx/nginx -o /usr/sbin/nginx
RUN chmod +x /usr/sbin/nginx
# Remove the stock nginx config file
RUN rm /etc/nginx/sites-enabled/default
COPY scripts/install_nginx.sh ./
RUN ./install_nginx.sh && rm ./install_nginx.sh

RUN mkdir -p /var/log/openlibrary /var/lib/openlibrary && chown openlibrary:openlibrary /var/log/openlibrary /var/lib/openlibrary \
&& mkdir /openlibrary && chown openlibrary:openlibrary /openlibrary \
Expand Down
3 changes: 3 additions & 0 deletions docker/covers_nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ server {
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;

# Needed for logging/IP anonymization
include /olsystem/etc/nginx/logging_periodics.conf;
}

# Docker's internal load balancing ends up with unbalanced connections eventually.
Expand Down
6 changes: 5 additions & 1 deletion docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Needed for IP anonymization
load_module modules/ngx_http_js_module.so;

user www-data;

# XXX-Anand: Oct 2013
Expand Down Expand Up @@ -25,7 +28,8 @@ http {
server_names_hash_bucket_size 64;
types_hash_bucket_size 64;

log_format iacombined '$remote_addr_ipscrub $host $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_time';
# Logging / IP Anonymization; also need logging_periodics.conf inside a server block
include /olsystem/etc/nginx/logging.conf;
access_log /var/log/nginx/access.log iacombined;

client_max_body_size 50m;
Expand Down
3 changes: 3 additions & 0 deletions docker/web_nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ server {
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;

# Needed for logging/IP anonymization
include /olsystem/etc/nginx/logging_periodics.conf;
}

server {
Expand Down
19 changes: 19 additions & 0 deletions scripts/install_nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /bin/bash

apt-get update

# log rotation service for ol-nginx
# rsync service for pulling monthly sitemaps from ol-home0 to ol-www0
apt-get install -y --no-install-recommends curl \
logrotate \
rsync \
lsb-release

# Add the NGINX signing key + Repo
curl -fsSL https://nginx.org/keys/nginx_signing.key | tee /usr/share/keyrings/nginx-keyring.asc
echo "deb [signed-by=/usr/share/keyrings/nginx-keyring.asc] http://nginx.org/packages/debian $(lsb_release -cs) nginx" \
> /etc/apt/sources.list.d/nginx.list

# Install nginx and the NJS module
apt-get update
apt-get install -y --no-install-recommends nginx nginx-module-njs letsencrypt
14 changes: 0 additions & 14 deletions scripts/install_openresty.sh

This file was deleted.

0 comments on commit 0045f02

Please sign in to comment.