[ prog / sol / mona ]

prog


How can I run my own instance of this

142 2020-04-11 01:54 *

>>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)

143 2020-04-11 02:04 *

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

301


VIP:

do not edit these