- Change BACKEND_PORT from 8001 to 5001 (same as Flask) - Keeps existing Azure AD redirect URI working - No need to update Azure AD app registration - Apache proxy can use same port configuration Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
155 lines
4.4 KiB
Markdown
155 lines
4.4 KiB
Markdown
# Apache Configuration Migration Guide
|
|
|
|
## ⚠️ Important Changes for FastAPI
|
|
|
|
Your current Apache config uses **Flask on port 5001**. For FastAPI, you need to change:
|
|
|
|
**Note:** Using **port 5001** (same as Flask) for Azure AD compatibility
|
|
|
|
### Current (Flask):
|
|
```apache
|
|
ProxyPass /solventum-image-metadata/ http://localhost:5001/
|
|
ProxyPassReverse /solventum-image-metadata/ http://localhost:5001/
|
|
```
|
|
|
|
### New (FastAPI):
|
|
```apache
|
|
# Frontend - static files (React build)
|
|
Alias /solventum-image-metadata /var/www/html/solventum-image-metadata
|
|
|
|
<Directory /var/www/html/solventum-image-metadata>
|
|
Options -Indexes +FollowSymLinks
|
|
AllowOverride All
|
|
Require all granted
|
|
|
|
# React Router (SPA) - rewrite to index.html
|
|
RewriteEngine On
|
|
RewriteBase /solventum-image-metadata
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
RewriteCond %{REQUEST_URI} !^/solventum-image-metadata/api/
|
|
RewriteRule ^ /solventum-image-metadata/index.html [L]
|
|
</Directory>
|
|
|
|
# Backend API - proxy to FastAPI
|
|
ProxyPreserveHost On
|
|
ProxyTimeout 600
|
|
|
|
<Location /solventum-image-metadata/api>
|
|
ProxyPass http://localhost:5001
|
|
ProxyPassReverse http://localhost:5001
|
|
|
|
RequestHeader set X-Forwarded-Proto "https"
|
|
RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s"
|
|
</Location>
|
|
```
|
|
|
|
## Key Changes:
|
|
|
|
1. **Port unchanged**: 5001 (same port as Flask for Azure AD compatibility)
|
|
2. **Frontend**: Separate static files (not proxied)
|
|
3. **API prefix**: `/solventum-image-metadata/api/` → Backend
|
|
4. **SPA routing**: RewriteRule for React Router
|
|
|
|
## Update on Server:
|
|
|
|
```bash
|
|
# 1. Edit Apache config
|
|
sudo nano /etc/apache2/sites-available/solventum-image-metadata.conf
|
|
|
|
# 2. Replace the ProxyPass lines with the new config above
|
|
|
|
# 3. Enable required modules
|
|
sudo a2enmod rewrite headers alias
|
|
|
|
# 4. Test config
|
|
sudo apache2ctl configtest
|
|
|
|
# 5. Reload Apache
|
|
sudo systemctl reload apache2
|
|
```
|
|
|
|
## Update .env on Server:
|
|
|
|
```bash
|
|
# Edit /opt/solventum-image-metadata/.env
|
|
sudo nano /opt/solventum-image-metadata/.env
|
|
|
|
# Change REDIRECT_URI:
|
|
REDIRECT_URI=https://ai-sandbox.oliver.solutions/solventum-image-metadata/api/auth/microsoft/callback
|
|
# ^^^^ ADD /api/
|
|
```
|
|
|
|
## Verify:
|
|
|
|
```bash
|
|
# Backend health (direct)
|
|
curl http://localhost:5001/health
|
|
|
|
# Frontend (through Apache)
|
|
curl https://ai-sandbox.oliver.solutions/solventum-image-metadata/
|
|
|
|
# API (through Apache)
|
|
curl https://ai-sandbox.oliver.solutions/solventum-image-metadata/api/health
|
|
```
|
|
|
|
## Complete Apache VirtualHost Example:
|
|
|
|
```apache
|
|
<VirtualHost *:443>
|
|
ServerName ai-sandbox.oliver.solutions
|
|
|
|
SSLEngine on
|
|
SSLCertificateFile /etc/letsencrypt/live/ai-sandbox.oliver.solutions/fullchain.pem
|
|
SSLCertificateKeyFile /etc/letsencrypt/live/ai-sandbox.oliver.solutions/privkey.pem
|
|
|
|
# Security headers
|
|
Header always set X-Frame-Options "SAMEORIGIN"
|
|
Header always set X-Content-Type-Options "nosniff"
|
|
|
|
# Frontend - React SPA static files
|
|
Alias /solventum-image-metadata /var/www/html/solventum-image-metadata
|
|
|
|
<Directory /var/www/html/solventum-image-metadata>
|
|
Options -Indexes +FollowSymLinks
|
|
AllowOverride All
|
|
Require all granted
|
|
|
|
# React Router support
|
|
RewriteEngine On
|
|
RewriteBase /solventum-image-metadata
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
RewriteCond %{REQUEST_URI} !^/solventum-image-metadata/api/
|
|
RewriteRule ^ /solventum-image-metadata/index.html [L]
|
|
</Directory>
|
|
|
|
# Cache static assets
|
|
<FilesMatch "\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$">
|
|
Header set Cache-Control "public, max-age=31536000"
|
|
</FilesMatch>
|
|
|
|
# Don't cache HTML
|
|
<FilesMatch "\.(html)$">
|
|
Header set Cache-Control "no-cache, no-store, must-revalidate"
|
|
</FilesMatch>
|
|
|
|
# Backend API - FastAPI reverse proxy
|
|
ProxyPreserveHost On
|
|
ProxyTimeout 600
|
|
|
|
<Location /solventum-image-metadata/api>
|
|
ProxyPass http://localhost:5001
|
|
ProxyPassReverse http://localhost:5001
|
|
|
|
RequestHeader set X-Forwarded-Proto "https"
|
|
RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s"
|
|
</Location>
|
|
|
|
# Allow large file uploads (500MB)
|
|
LimitRequestBody 524288000
|
|
|
|
ErrorLog ${APACHE_LOG_DIR}/solventum-image-metadata-error.log
|
|
CustomLog ${APACHE_LOG_DIR}/solventum-image-metadata-access.log combined
|
|
</VirtualHost>
|
|
```
|