# 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 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] # Backend API - proxy to FastAPI ProxyPreserveHost On ProxyTimeout 600 ProxyPass http://localhost:5001 ProxyPassReverse http://localhost:5001 RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s" ``` ## 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 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 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] # Cache static assets Header set Cache-Control "public, max-age=31536000" # Don't cache HTML Header set Cache-Control "no-cache, no-store, must-revalidate" # Backend API - FastAPI reverse proxy ProxyPreserveHost On ProxyTimeout 600 ProxyPass http://localhost:5001 ProxyPassReverse http://localhost:5001 RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}s" # 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 ```