>>26
I've added those lines to the top of the server section of an nginx.conf file, and it does seem to work (after installing the nginx module posted by >>29).
My only question is about the first line: What is the value of the bypass variable? I assume that it would be some sort of match for pages that do not make use of the shared CSS files, but it would be nice to know if there's more to it.
>>140
Also, sorry to be somewhat offtopic, but as another anon said this has become something of a bug report thread.
Right now all of the threads on https://textboard.org/prog/list/ are being linked to incorrectly.
This seems to be caused by the last "/" in the URL.
>>140
There are two modules used:
https://github.com/yaoweibin/ngx_http_substitutions_filter_module
https://github.com/aperezdc/ngx-fancyindex
The first one is used for the ``css toggle without cookies'' hack and the second is just to make nice directory listings.
I think some variables were missing in the post where I explained the css switching, so here's the part that takes care of adding the query strings to all links:
server {
if ( $query_string = "" )
{
set $bypass "1";
}
#replace css and add query string to all internal links
subs_filter_bypass $bypass;
subs_filter '<LINK href="/static/styles/(.*?).css"' '<LINK href="/static/styles/$arg_css.css"' or;
subs_filter '<A href="((?!http).*?)(#.*?)?"' '<A href="$1$is_args$args$2"' gr;
subs_filter '<FORM action="(.*?post)"' '<FORM action="$1$is_args$args"' gr;
}
I call it a hack because in a perfect world, elements of your app should be loosely coupled and SchemeBBS would handle this, not Nginx. But sometimes you have to chose the way of the ninja especially for nice but non vital features.
cont. (I hit the post length limit. I got a new server today with decent specs so the site will be migrated and the post limit raised)
>>140,142
You'll also probably want to serve static files directly with nginx, even if SchemeBBS can serve them too. And you probably want to cache requests. So, here's a fairly complete nginx.conf
:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
proxy_cache_path /var/cache/nginx levels=1:2
keys_zone=cache:10m inactive=600s max_size=100m;
#limit post requests
map $request_method $limit {
default "";
POST $binary_remote_addr;
}
# Creates 10mb zone in memory for storing binary ips
limit_req_zone $limit zone=post_limit:10m rate=11r/m;
upstream http_backend {
keepalive 20;
server 127.0.0.1:8080;
}
server {
listen 80;
server_name tld.org www.tld.org;
set $prefix "/path/to/schemebbs"
# site root, a static page
location = / {
rewrite ^ /static/index.html;
}
location = /favicon.ico {
rewrite ^ /static/favicon.ico;
}
# static files
location /static/ {
alias $prefix/static/;
}
# serve s-expressions as static files
location /sexp {
alias $prefix/data/sexp/;
autoindex on;
default_type text/x-scheme;
fancyindex on;
fancyindex_time_format "%F %R";
fancyindex_footer "/static/lisp.html";
}
location / {
root $prefix/data/html;
default_type text/html;
index index;
try_files $uri $uri/index @schemebbs;
}
#replace css and add query string to all internal links
#snippet above goes here
location @schemebbs {
proxy_intercept_errors on;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache cache;
proxy_cache_key $scheme$host$request_method$request_uri;
proxy_cache_valid 200 30s;
proxy_pass http://http_backend;
}
error_page 400 /400.html;
error_page 403 /403.html;
error_page 404 /404.html;
error_page 405 /405.html;
error_page 500 /500.html;
error_page 502 /502.html;
error_page 503 /503.html;
error_page 504 /504.html;
error_page 429 /429.html;
location ~ ^/(400|403|404|405|429|500|502|503|504)\.html {
root $prefix/static/errors;
}
}#end server
}#end http
>>140
As you can see, with the try_files
directive, Nginx will first search for the file to serve it without calling Scheme and if it can't find the resource asked, the request is passed to SchemeBBS. Threads, index and thread list are generated on demand and not after posting, once again because of performance considerations. The modest webapp runs on the good old academic MIT Scheme, not Scala or node.js. I didn't want to let the poster wait with a "That was VIP quality/here's a candle flag on the Moon" message trick. Users don't like to wait.
Right now all of the threads on https://textboard.org/prog/list/ are being linked to incorrectly. This seems to be caused by the last "/" in the URL
Indeed, it shouldn't be hard to fix. It's funny nobody noticed earlier, thanks.