changed 5 months ago
Linked with GitHub

Apache v2

Debian

Configuration

  • /var/www/html document root
  • /var/log/apache2 log
  • /etc/apache2/
    • apache2.conf
    • ports.conf
    • {mods | conf | sites}-{enabled | available}/
# clear error log
sudo bash -c 'echo > /var/log/apache2/error.log'

Enable SSL

  • self-signed certificate
    • hostname as currently configured on the computer
  • default files
    • /etc/ssl/certs/ssl-cert-snakeoil.pem
    • /etc/ssl/private/ssl-cert-snakeoil.key
sudo make-ssl-cert generate-default-snakeoil --force-overwrite

sudo a2ensite default-ssl
sudo a2enmod ssl

sudo service apache2 restart
// or
sudo systemctl restart apache2

VHost Alias / Proxy / Rewrite

  • serve blog.EXAMPLE.COM from /var/www/subdomain/blog
  • reverse proxy requests to blog.EXAMPLE.COM/api
# enable VirtualDocumentRoot
sudo a2enmod vhost_alias
# enable ProxyDIRECTIVE
sudo a2enmod proxy
sudo a2enmod proxy_http
# enable RewriteDIRECTIVE
sudo a2enmod rewrite

cd /etc/apache2/sites-available/
sudo cp default-ssl.conf subdomain-ssl.conf
sudo vi subdomain-ssl.conf

sudo service apache2 restart

cd /var/www
mkdir subdomain
# subdomain-ssl.conf
<VirtualHost *:443>
    ServerName blog.EXAMPLE.COM
    VirtualDocumentRoot /var/www/subdomain/%1

    ProxyRequests Off
    ProxyPass /api DEST
    ProxyPassReverse /api DEST

    <Directory ".">
        RewriteEngine On

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . index.html [L]
    </Directory>
    
    # ...
</VirtualHost>
  • VHost Alias
    • VirtualDocumentRoot
      • %1 replaced by blog (the first part of blog.EXAMPLE.COM)
  • Proxy
    • ProxyRequests Off disable forward proxy / perform reverse proxy
    • ProxyPreserveHost On pass Host: blog.EXAMPLE.COM instead of Host: DEST
  • Rewrite
    • RewriteCond TARGET PATTERN [[FLAG]]
    • RewriteRule PATTERN SUBSTITUTION [[FLAG]]

相關資源

Select a repo