HowTo/HostAPastebinWebsiteIntoI2P

From I2P Wiki
Jump to navigation Jump to search

Introduction

Text copied from http://kytv.i2p (down since march 2016).

Content

This is a cached copy of http://killyourtv.i2p/howtos/pastebin/ It is a snapshot of the page as it appeared on 2014-05-17 07:18:45 UTC, all scripts and css links are stripped out. killyourtv.i2p/ howtos/ Set up your own pastebin

Intro

This guide (recommended by zab) will walk you through a possible configuration of nginx and uwsgi for LodgeIt, the software used by pastethis.i2p. These instructions are geared toward Debian systems but can be used elsewhere with minor modifications.

Get the Source

The source code for LodgeIt is managed using Mercurial. You can install Mercurial and checkout the source code with:

apt-get install mercurial ca-certificates
hg clone https://bitbucket.org/EnTeQuAk/lodgeit-main

Zoltan added line-wrap support to LodgeIt (thanks!). The combined patchset is available from paste #1956. Save the patch to the lodgeit-main directory and apply it with

patch -p1 < patchfile

.

By this point the ‘development server’ can be run by following the instructions in upstream’s readme. For production use, running LodgeIt as a WSGI application is recommended.

Set-up for Production

Installing pre-requisites and configuring LodgeIt

The required pacakges can be installed with

apt-get install python-werkzeug python-sqlalchemy nginx-full python-jinja2 python-markupsafe python-imaging \
       python-pygments ttf-bitstream-vera python-babel python-simplejson python-setuptools uwsgi uwsgi-plugin-python

cd into the lodgeit-main directory. If you’d like to politely ask web-crawlers to not crawl your pastebin, create a robots.txt file:

cat > lodgeit/static/robots.txt << EOF
User-agent: *
Disallow: /
EOF

Create the WSGI file:

cat > lodgeit.wsgi  << EOF
import sys
import os
sys.path.append(os.path.dirname(__file__))
from lodgeit import make_app

application = make_app(
# the path to the database
dburi='sqlite:////var/lib/lodgeit/lodgeit.db',
secret_key=$(python -c 'import os; print repr(os.urandom(30))')
)
EOF

Check to make sure that secret_key was defined (grep secret_key lodgeit.wsgi). You should have something like the following returned (do NOT use this string if not):

secret_key='r\xcaq\xbc\xd68\xe5z\xd0_n\x99\x11+\xb8\x8b\x06\xdc\x7f\x0b\x17\xde_\x00E\xf9\xcd-Lx'

Move the lodgeit directory to its final destination and change the owner/group to www-data. For example, I moved the LodgeIt installation to /usr/local and did the following:

cd ..
mv lodgeit-main /usr/local/lodgeit
mkdir /var/lib/lodgeit
chown -R www-data:www-data /usr/local/lodgeit /var/lib/lodgeit

Configuring nginx

Create the site configuration file:

cat > /etc/nginx/sites-available/pastebin << EOF
server {
        listen   5000; ## listen for ipv4; this line is default and implied

        root /usr/local/lodgeit;
        access_log /var/log/nginx/pastebin_access.log i2p;
        error_log /var/log/nginx/pastebin_error.log warn;

        # Make site accessible from http://localhost/
        # Be sure to add other hosts that this will be reachable from, such
        # as your b32 or hostname
        #
        server_name localhost;

        location / {
                uwsgi_pass unix:///run/uwsgi/app/pastebin/socket;
                include uwsgi_params;
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }

        location ~ /\.ht {
                deny all;
        }

        if (\$request_method !~ ^(GET|HEAD|POST)\$ ) {
                return 405;
        }

        location /static/ {
                root /usr/local/lodgeit/lodgeit;
                expires max;
        }

       location ~ \.(aspx|php|jsp|cgi)\$ {
               return 501;
       }

       location ~ /Seedless {
               return 501;
       }

       # Uncomment this stanza if you want to use a robots.txt file
       #
       # location /robots.txt {
       #        rewrite /robots.txt /static/robots.txt;
       #}
}
EOF

Create the I2P logging definition with

cat > /etc/nginx/conf.d/i2p_logging.conf  << EOF

log_format i2p '\$remote_addr \$http_x_i2p_destb32 - \$remote_user [\$time_local] '
    '"\$request" \$status \$body_bytes_sent '
    '"\$http_referer" "\$http_user_agent"';
EOF

Finally, enable your new pastebin site with (as root)

ln -s /etc/nginx/sites-available/pastebin /etc/nginx/sites-enabled
service nginx restart

Configuring UWSGI

Create the UWSGI pastebin configuration file with

cat > /etc/uwsgi/apps-available/pastebin.ini << EOF
[uwsgi]
wsgi-file = /usr/local/lodgeit/lodgeit.wsgi
EOF

…then enable the application with

ln -s /etc/uwsgi/apps-available/pastebin.ini /etc/uwsgi/apps-enabled
service uwsgi restart

You should now be able to access your new pastebin from http://127.0.0.1:5000.

References


See also

External links