Static Site Generator

How-to: How to use Stapy with Apache HTTP Server?

How to use Stapy with Apache HTTP Server?

Stapy can be hosted on a remote server, as a proxy behind Apache. This can be usefull to:

You can use a protected subdomain to manage and preview pages, and access the published static site on the main domain.

Stapy service

Add your Stapy site in the /var/www/stapy directory. Give on the directory the permissions for the user who will launch Stapy. Create a specific user and group for Stapy if needed. Example:

chown -R stapy:stapy /var/www/stapy

On a distribution with systemd, create a new script to start Stapy:

nano /etc/init.d/
python3 /var/www/stapy/ > /dev/null &

Note: On some systems the command can be python instead of python3.

chmod +x /etc/init.d/

Create a Unit file to define a systemd service:

nano /lib/systemd/system/stapy.service


Note: Update the User and the Group with the appropriate values.

chmod 644 /lib/systemd/system/stapy.service

Once you have a unit file, you are ready to start Stapy:

systemctl start stapy

Check the status of the service:

systemctl status stapy

Apache vhost

We need to use Stapy service as a proxy with Apache. Add a new Apache vhost file:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost


    ErrorLog ${APACHE_LOG_DIR}/stapy-error.log
    CustomLog ${APACHE_LOG_DIR}/stapy-access.log combined        

    LogLevel warn

    RewriteEngine On
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*) ws://$1 [P,L]
    ProxyRequests off
    ProxyPass /
    ProxyPassReverse /
    ProxyPreserveHost On

Use Let's Encrypt to create a specific vhost for SSL.

Enable host and restart Apache. You can now access Stapy from your subdomain (e.g.,

We recommand to protect this host with IP restriction or htpasswd.

Add now a new vhost to share the result of building your site on the main domain:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/stapy/web/prod

    <Directory /var/www/stapy/web/prod>
        Options Indexes FollowSymLinks MultiViews

Don't forget to add cache and security policies (mod_headers.c, mod_expires.c...).