Virtual Host And Certbot in WSL2

From Chorke Wiki
Jump to navigation Jump to search
a2enmod proxy;\
a2enmod proxy_http;\
a2enmod proxy_balancer;\
a2enmod lbmethod_byrequests;\
service apache2 restart

Config

config locations:
mkdir -p /mnt/d/usr/share/apache2/icons
mkdir -p /mnt/d/etc/apache2/conf.sites.all.d
virtual site config:
touch /mnt/d/etc/apache2/conf.sites.all.d/00-dev.chorke.org{.conf,-le-ssl.conf}
touch /mnt/d/etc/apache2/conf.sites.all.d/01-api.chorke.org{.conf,-le-ssl.conf}
touch /mnt/d/etc/apache2/conf.sites.all.d/02-dev.chorke.com{.conf,-le-ssl.conf}
touch /mnt/d/etc/apache2/conf.sites.all.d/03-dev.shahed.biz{.conf,-le-ssl.conf}
virtual site locations:
mkdir -p /mnt/d/var/www/dev.chorke.com/{docs,html,logs,soft}
mkdir -p /mnt/d/var/www/dev.shahed.biz/{docs,html,logs,soft}
mkdir -p /mnt/d/var/www/{api,dev}.chorke.org/{docs,html,logs,soft}

mkdir -p /mnt/d/var/www/dev.chorke.com/html/.well-known/acme-challenge
mkdir -p /mnt/d/var/www/dev.shahed.biz/html/.well-known/acme-challenge
mkdir -p /mnt/d/var/www/{api,dev}.chorke.org/html/.well-known/acme-challenge

Enable

cd /etc/apache2/sites-enabled/
ln -s /mnt/d/etc/apache2/conf.sites.all.d/00-dev.chorke.org.conf 00-dev.chorke.org.conf
ln -s /mnt/d/etc/apache2/conf.sites.all.d/01-api.chorke.org.conf 01-api.chorke.org.conf
ln -s /mnt/d/etc/apache2/conf.sites.all.d/02-dev.chorke.com.conf 02-dev.chorke.com.conf
ln -s /mnt/d/etc/apache2/conf.sites.all.d/03-dev.shahed.biz.conf 03-dev.shahed.biz.conf
cd /etc/apache2/sites-enabled/
ln -s /mnt/d/etc/apache2/conf.sites.all.d/00-dev.chorke.org-le-ssl.conf 00-dev.chorke.org-le-ssl.conf
ln -s /mnt/d/etc/apache2/conf.sites.all.d/01-api.chorke.org-le-ssl.conf 01-api.chorke.org-le-ssl.conf
ln -s /mnt/d/etc/apache2/conf.sites.all.d/02-dev.chorke.com-le-ssl.conf 02-dev.chorke.com-le-ssl.conf
ln -s /mnt/d/etc/apache2/conf.sites.all.d/03-dev.shahed.biz-le-ssl.conf 03-dev.shahed.biz-le-ssl.conf

Virtual Host configuration skipped to avoid redundancy. Please find the config details in Virtual Host And Certbot in Raspbian 10.

Virtual Host

cat <<EOF >> /mnt/d/etc/apache2/conf.sites.all.d/03-dev.shahed.biz.conf
<IfModule mod_proxy.c>
<VirtualHost *:80>
    ProxyRequests Off
    ProxyPreserveHost On
    AllowEncodedSlashes Off
    ServerAdmin info@shahed.biz

    DocumentRoot /mnt/d/var/www/dev.shahed.biz/html
    ErrorLog /mnt/d/var/www/dev.shahed.biz/logs/error.log
    CustomLog /mnt/d/var/www/dev.shahed.biz/logs/requests.log combined

    <Directory "/mnt/d/var/www/dev.shahed.biz/">
        AllowOverride None
        Require all granted
    </Directory>

    <Directory "/mnt/d/var/www/dev.shahed.biz/html">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    Alias /docs "/mnt/d/var/www/dev.shahed.biz/docs/"
    <Directory "/mnt/d/var/www/dev.shahed.biz/docs">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Require all granted
        Order Allow,Deny
        Allow from all
    </Directory>

    Alias /logs "/mnt/d/var/www/dev.shahed.biz/logs/"
    <Directory "/mnt/d/var/www/dev.shahed.biz/logs">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Require all granted
        Order Allow,Deny
        Allow from all
    </Directory>

    Alias /soft "/mnt/d/var/www/dev.shahed.biz/soft/"
    <Directory "/mnt/d/var/www/dev.shahed.biz/soft">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Require all granted
        Order Allow,Deny
        Allow from all
    </Directory>

    <Proxy *>
        Order Allow,Deny
        Allow from all
        Deny from 10.9.8
    </Proxy>

#    RewriteEngine on
#    RewriteCond %{SERVER_NAME} =dev.shahed.biz [OR]
#    RewriteCond %{SERVER_NAME} =www.dev.shahed.biz
#    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
</IfModule>
EOF

PgAdmin4

apt install python3 python3-pip libgmp3-dev libpq-dev libapache2-mod-wsgi-py3;\
apt install python3-venv;python3 -m venv /mnt/d/var/www/dev.shahed.biz/pgadmin4;\
source /mnt/d/var/www/dev.shahed.biz/pgadmin4/bin/activate

python3 -m pip install -U pip; python3 -m pip install wheel;\
python3 -m pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v5.4/pip/pgadmin4-5.4-py3-none-any.whl

mkdir /mnt/d/var/log/pgadmin4; mkdir -p /mnt/d/var/lib/pgadmin4/{sessions,storage};\
chown -R www-data:www-data /mnt/d/var/{lib,log}/pgadmin4
cat <<EOF >> /mnt/d/var/www/dev.shahed.biz/pgadmin4/lib/python3.8/site-packages/pgadmin4/config_local.py
SESSION_DB_PATH = '/mnt/d/var/lib/pgadmin4/sessions'
SQLITE_PATH = '/mnt/d/var/lib/pgadmin4/pgadmin4.db'
LOG_FILE = '/mnt/d/var/log/pgadmin4/pgadmin4.log'
STORAGE_DIR = '/mnt/d/var/lib/pgadmin4/storage'
DATA_DIR = '/mnt/d/var/lib/pgadmin4/datadir'
UPGRADE_CHECK_ENABLED = False
SERVER_MODE = True
EOF
python /mnt/d/var/www/dev.shahed.biz/pgadmin4/lib/python3.8/site-packages/pgadmin4/setup.py
: <<'END_COMMENT'
NOTE: Configuring authentication for SERVER mode.

Enter the email address and password to use for the initial pgAdmin user account:

Email address: info<at>shahed.biz
Password:
Retype password:
pgAdmin 4 - Application Initialisation
======================================
END_COMMENT
deactivate

Apache Config

WSGIDaemonProcess pgadmin processes=1 threads=25 python-home=/mnt/d/var/www/dev.shahed.biz/pgadmin4
WSGIScriptAlias /pgadmin4 "/mnt/d/var/www/dev.shahed.biz/pgadmin4/lib/python3.8/site-packages/pgadmin4/pgAdmin4.wsgi"
<Directory "/mnt/d/var/www/dev.shahed.biz/pgadmin4/lib/python3.8/site-packages/pgadmin4/">
    WSGIProcessGroup pgadmin
    WSGIApplicationGroup %{GLOBAL}
    Require all granted
</Directory>

Alias Config

# vim /etc/apache2/mods-enabled/alias.conf
<IfModule alias_module>
    Alias /icons/ "/mnt/d/usr/share/apache2/icons/"
    <Directory "/mnt/d/usr/share/apache2/icons">
        Options FollowSymlinks Indexes MultiViews
        AllowOverride None
        Require all granted
    </Directory>
</IfModule>

Auto Index

vim /etc/apache2/mods-enabled/autoindex.conf

<IfModule mod_autoindex.c>
    # Directives controlling the display of server-generated directory listings.

    #
    # IndexOptions: Controls the appearance of server-generated directory
    # listings.
    # Remove/replace the "Charset=UTF-8" if you don't use UTF-8 for your filenames.
    IndexOptions FancyIndexing VersionSort HTMLTable NameWidth=* DescriptionWidth=* Charset=UTF-8 SuppressDescription SuppressRules FoldersFirst XHTML
    IndexStyleSheet /icons/style.css

    #
    # AddIcon* directives tell the server which icon to show for different
    # files or filename extensions.  These are only displayed for
    # FancyIndexed directories.
    AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip x-bzip2

    AddIconByType (TXT,/icons/text.gif) text/*
    AddIconByType (IMG,/icons/image.gif) image/*
    AddIconByType (SND,/icons/sound.gif) audio/*
    AddIconByType (VID,/icons/movie.gif) video/*
    AddIconByType (HTML,/icons/html.gif) text/html

    AddIcon /icons/binary.gif .bin .exe .so .dll
    AddIcon /icons/binhex.gif .hqx
    AddIcon /icons/tar.gif .tar
    AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
    AddIcon /icons/compressed.gif .Z .z .7z .tgz .gz .zip
    AddIcon /icons/a.gif .ps .ai .eps .doc .psd .docx
    AddIcon /icons/html.gif .html .shtml .htm .css .xml .xhtml .chm
    AddIcon /icons/pdf.gif .pdf
    AddIcon /icons/log.gif .log
    AddIcon /icons/c.gif .c .cpp .c++ .h
    AddIcon /icons/pl.gif .pl
    AddIcon /icons/py.gif .py .pyc
    AddIcon /icons/spy.gif .spy
    AddIcon /icons/php.gif .php
    AddIcon /icons/cgi.gif .cgi
    AddIcon /icons/f.gif .for
    AddIcon /icons/dvi.gif .dvi
    AddIcon /icons/uuencoded.gif .uu
    AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl .cmd .bat
    AddIcon /icons/jar.gif .jar
    AddIcon /icons/pom.gif .pom
    AddIcon /icons/md5.gif .md5
    AddIcon /icons/sha1.gif .sha1
    AddIcon /icons/tex.gif .tex
    # It's a suffix rule, so simply matching "core" matches "score" as well !
    AddIcon /icons/bomb.gif /core
    AddIcon (SND,/icons/sound.gif) .ogg
    AddIcon (VID,/icons/movie.gif) .ogm

    AddIcon /icons/back.gif ..
    AddIcon /icons/hreadme.gif readme README
    AddIcon /icons/folder.gif ^^DIRECTORY^^
    AddIcon /icons/folder.open.gif ^^BLANKICON^^

    # Default icons for OpenDocument format
    AddIcon /icons/odf6odt-20x22.png .odt
    AddIcon /icons/odf6ods-20x22.png .ods
    AddIcon /icons/odf6odp-20x22.png .odp
    AddIcon /icons/odf6odg-20x22.png .odg
    AddIcon /icons/odf6odc-20x22.png .odc
    AddIcon /icons/odf6odf-20x22.png .odf
    AddIcon /icons/odf6odb-20x22.png .odb
    AddIcon /icons/odf6odi-20x22.png .odi
    AddIcon /icons/odf6odm-20x22.png .odm

    AddIcon /icons/odf6ott-20x22.png .ott
    AddIcon /icons/odf6ots-20x22.png .ots
    AddIcon /icons/odf6otp-20x22.png .otp
    AddIcon /icons/odf6otg-20x22.png .otg
    AddIcon /icons/odf6otc-20x22.png .otc
    AddIcon /icons/odf6otf-20x22.png .otf
    AddIcon /icons/odf6oti-20x22.png .oti
    AddIcon /icons/odf6oth-20x22.png .oth

    #
    # DefaultIcon is which icon to show for files which do not have an icon
    # explicitly set.
    DefaultIcon /icons/unknown.gif

    #
    # AddDescription allows you to place a short description after a file in
    # server-generated indexes.  These are only displayed for FancyIndexed
    # directories.
    # Format: AddDescription "description" filename
    AddDescription "Readme File" readme
    AddDescription "Core File" core
    AddDescription "GZIP compressed document" .gz
    AddDescription "GZIP compressed tar archive" .tgz
    AddDescription "Tar archive" .tar
    AddDescription "Zip Archive" .zip
    AddDescription "<a href=\"http://www.apple.com/quicktime/\" title=\"Quicktime\">QuickTime</a> Movie" .mov
    AddDescription "<a href=\"http://www.real.com/\" title=\"RealNetworks\">RealNetworks</a> Movie" .ra .ram
    AddDescription "Plain-text Document" .txt
    AddDescription "Web document" .HTML .xhtml
    AddDescription "Compile HTML" .chm .CHM
    AddDescription "Document" .ps .ai .eps .pdf .psd .doc .docx
    AddDescription "Binary File" .bin .exe .so .dll .pyc .class
    AddDescription "Log File" .log
    AddDescription "MD5 Digest" .md5 .jar.md5 .pom.md5
    AddDescription "SHA1 Digest" .sha1 .jar.sha1 pom.sha1
    AddDescription "Java Archive" .jar
    AddDescription "Maven pom" .pom
    AddDescription "Script" .conf .sh .shar .csh .ksh .tcl .cmd .bat
    AddDescription "PHP Script" .php
    AddDescription "Perl Script" .pl
    AddDescription "Pyhon Script" .py .spy
    AddDescription "C Script" .cpp .c++
    AddDescription "3D World" .wrl .wrl.gz .vrml .vrm .iv
    AddDescription "Icon" .ico
    AddDescription "<acronym title=\"Motion Picture Experts Group Audio Layer 3\">MP3</acronym> Audio File" .mp3
    AddDescription "<acronym title=\"HyperText Markup Language\">HTML</acronym> Page" .html .htm .shtml
    AddDescription "<acronym title=\"Portable Network Graphics\">PNG</acronym> Image" .png
    AddDescription "<acronym title=\"Graphics Interchange Format\">GIF</acronym> Image" .gif
    AddDescription "<acronym title=\"Joint Photographic Experts Group\">JPEG</acronym> Image" .jpg .jpeg
    AddDescription "<acronym title=\"Bitmap\">BMP</acronym> Image" .bmp
    AddDescription "<acronym title=\"Extensive Markup Language\">XML</acronym> File" .xml
    AddDescription "<acronym title=\"Common Gateway Interface\">CGI</acronym> parsed script" .cgi
    AddDescription "<acronym title=\"Cascading Style Sheet\">CSS</acronym> File" .css

    #
    # ReadmeName is the name of the README file the server will look for by
    # default, and append to directory listings.
    #
    # HeaderName is the name of a file which should be prepended to
    # directory indexes
    ReadmeName /icons/README.html
    HeaderName HEADER.html

    #
    # IndexIgnore is a set of filenames which directory indexing should ignore
    # and not include in the listing.  Shell-style wildcarding is permitted.
    IndexIgnore .??* *~ *# RCS CVS *,v *,t HEADER.html README.html favicon.ico README cgi-bin

</IfModule>

Knowledge

sudo service apache2 restart
sudo service redis-server restart

References