|
| 1 | +# SQLPage with Apache Reverse Proxy |
| 2 | + |
| 3 | +This example demonstrates how to run SQLPage behind the popular Apache HTTP Server. |
| 4 | +This is particularly useful when you already have a server running Apache (with a PHP application for example) |
| 5 | +and you want to add a SQLPage application. |
| 6 | + |
| 7 | +This setup allows you to: |
| 8 | +- Host multiple websites/applications on a single server |
| 9 | +- Serve static files directly through Apache |
| 10 | +- Route specific paths to SQLPage |
| 11 | + |
| 12 | +## How it Works |
| 13 | + |
| 14 | +Apache acts as a reverse proxy, forwarding requests for `/my_website` to the SQLPage |
| 15 | +application while serving static content directly. The configuration uses: |
| 16 | + |
| 17 | +- [`mod_proxy`](https://httpd.apache.org/docs/current/mod/mod_proxy.html) and [`mod_proxy_http`](https://httpd.apache.org/docs/current/mod/mod_proxy_http.html) for reverse proxy functionality |
| 18 | +- [Virtual hosts](https://httpd.apache.org/docs/current/vhosts/) for domain-based routing |
| 19 | +- [`ProxyPass`](https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass) directives to forward specific paths |
| 20 | + |
| 21 | +## Docker Setup |
| 22 | + |
| 23 | +The `docker-compose.yml` defines three services: |
| 24 | +- `apache`: Serves static content and routes requests |
| 25 | +- `sqlpage`: Handles dynamic content generation |
| 26 | +- `mysql`: Provides database storage |
| 27 | + |
| 28 | +## Native Apache Setup |
| 29 | + |
| 30 | +To use this with a native Apache installation instead of Docker: |
| 31 | + |
| 32 | +1. Install Apache and required modules: |
| 33 | +```bash |
| 34 | +sudo apt install apache2 |
| 35 | +sudo a2enmod proxy proxy_http |
| 36 | +``` |
| 37 | + |
| 38 | +2. Configuration changes: |
| 39 | +- Place the `httpd.conf` content in `/etc/apache2/sites-available/my-site.conf` |
| 40 | +- Adjust paths: |
| 41 | + - Change `/var/www` to your static files location |
| 42 | + - Update SQLPage URL to match your actual SQLPage server address (`http://localhost:8080/my_website` if you are running sqlpage locally) |
| 43 | + - Modify log paths to standard Apache locations (`/var/log/apache2/`) |
| 44 | + |
| 45 | +3. SQLPage setup: |
| 46 | +- Install SQLPage on your server |
| 47 | +- Configure it with the same `site_prefix` in `sqlpage.json` |
| 48 | +- Ensure MySQL is accessible from the SQLPage instance |
| 49 | + |
| 50 | +4. Enable the site: |
| 51 | +```bash |
| 52 | +sudo a2ensite my-site |
| 53 | +sudo systemctl reload apache2 |
| 54 | +``` |
| 55 | + |
| 56 | +## Files Overview |
| 57 | + |
| 58 | +- `httpd.conf`: Apache configuration with proxy rules |
| 59 | +- `sqlpage_config/sqlpage.json`: SQLPage configuration with URL prefix |
| 60 | +- `static/`: Static files served directly by Apache |
| 61 | +- `website/`: SQLPage SQL files for dynamic content |
0 commit comments