Skip to content

Commit 8b245f5

Browse files
committed
add apache example
1 parent 1c2bc4e commit 8b245f5

File tree

6 files changed

+187
-0
lines changed

6 files changed

+187
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
2+
LoadModule proxy_module modules/mod_proxy.so
3+
LoadModule proxy_http_module modules/mod_proxy_http.so
4+
LoadModule unixd_module modules/mod_unixd.so
5+
LoadModule log_config_module modules/mod_log_config.so
6+
LoadModule authz_core_module modules/mod_authz_core.so
7+
LoadModule dir_module modules/mod_dir.so
8+
9+
<IfModule unixd_module>
10+
User daemon
11+
Group daemon
12+
</IfModule>
13+
14+
ServerName localhost
15+
Listen 80
16+
17+
DirectoryIndex index.html
18+
19+
ErrorLog /proc/self/fd/2
20+
LogLevel warn
21+
CustomLog /proc/self/fd/1 combined
22+
23+
<VirtualHost *:80>
24+
ServerName my_website
25+
DocumentRoot "/var/www"
26+
27+
ProxyPreserveHost On
28+
29+
<Location />
30+
Require all granted
31+
Options Indexes FollowSymLinks
32+
AllowOverride None
33+
</Location>
34+
35+
<Location /my_website>
36+
ProxyPass "http://sqlpage:8080/my_website"
37+
ProxyPassReverse "http://sqlpage:8080/my_website"
38+
</Location>
39+
</VirtualHost>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
sqlpage:
3+
image: lovasoa/sqlpage:main
4+
volumes:
5+
- ./sqlpage_config:/etc/sqlpage:ro
6+
- ./website:/var/www:ro
7+
environment:
8+
- DATABASE_URL=mysql://sqlpage:sqlpage_password@mysql:3306/sqlpage_db
9+
depends_on:
10+
- mysql
11+
12+
apache:
13+
image: httpd:2.4
14+
ports:
15+
- "80:80"
16+
volumes:
17+
- ./apache/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
18+
- ./static:/var/www:ro
19+
depends_on:
20+
- sqlpage
21+
22+
mysql:
23+
image: mysql:8
24+
environment:
25+
- MYSQL_ROOT_PASSWORD=root_password
26+
- MYSQL_DATABASE=sqlpage_db
27+
- MYSQL_USER=sqlpage
28+
- MYSQL_PASSWORD=sqlpage_password
29+
volumes:
30+
- mysql_data:/var/lib/mysql
31+
32+
volumes:
33+
mysql_data:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"site_prefix": "/my_website"
3+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Welcome</title>
7+
<style>
8+
body {
9+
font-family: system-ui, sans-serif;
10+
text-align: center;
11+
margin: 40px;
12+
background: #f5f5f5;
13+
}
14+
.main-link {
15+
display: inline-block;
16+
padding: 12px 24px;
17+
background: #4CAF50;
18+
color: white;
19+
text-decoration: none;
20+
border-radius: 4px;
21+
}
22+
.main-link:hover {
23+
background: #89ca8c;
24+
}
25+
.info {
26+
max-width: 600px;
27+
margin: 20px auto;
28+
color: #666;
29+
line-height: 1.5;
30+
}
31+
</style>
32+
</head>
33+
<body>
34+
<h1>Welcome to Our Site</h1>
35+
<p class="info">
36+
This page is served by Apache web server, which acts as a reverse proxy. When you click the button below,
37+
you'll be redirected to a SQLPage application running in a separate container. The setup includes three
38+
services: Apache for static content and routing, SQLPage for dynamic content, and MySQL for data storage.
39+
</p>
40+
<a href="/my_website" class="main-link">Enter Site</a>
41+
</body>
42+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
select
2+
'text' as component,
3+
true as article,
4+
'
5+
# Welcome to my website
6+
7+
Using SQLPage v' || sqlpage.version() || '
8+
9+
Connected to **MySQL** v' || version () as contents_md;

0 commit comments

Comments
 (0)