Created complete step-by-step guide for deploying Flask behind IIS. Covers: - IIS module installation (URL Rewrite, ARR) - ARR proxy configuration - Flask service setup with NSSM - IIS site configuration - End-to-end testing - Troubleshooting common issues - Maintenance commands - Security considerations - Performance tuning options - Backup and recovery Deployment architecture: Browser → IIS (HTTPS :443) → Reverse Proxy → Flask (HTTP :3001) → MySQL This is the complete production deployment guide for Windows Server environments where IIS must handle SSL/HTTPS public access. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
11 KiB
IIS Reverse Proxy Deployment Guide
Complete guide for deploying the Shopfloor Dashboard with IIS as a reverse proxy to Flask.
Architecture
[Browser] → [IIS :443 HTTPS] → [Reverse Proxy] → [Flask :3001 HTTP] → [MySQL]
- IIS: Handles HTTPS, SSL certificates, and public access
- Flask: Runs backend API on localhost:3001
- MySQL: Database (can be local or remote)
Prerequisites
- Windows Server 2016+ or Windows 10/11
- IIS installed with default features
- Python 3.8+ installed
- MySQL 5.6+ accessible
- Administrative access
Step 1: Install IIS Modules
1.1 Download and Install URL Rewrite
- Download: https://www.iis.net/downloads/microsoft/url-rewrite
- Run installer:
rewrite_amd64_en-US.msi - Accept defaults and install
1.2 Download and Install Application Request Routing (ARR)
- Download: https://www.iis.net/downloads/microsoft/application-request-routing
- Run installer:
ARR_3.0_amd64.exe - Accept defaults and install
1.3 Verify Installation
REM Open IIS Manager
inetmgr
You should see:
- "URL Rewrite" icon in IIS site features
- "Application Request Routing Cache" at server level
Step 2: Enable ARR Proxy
In IIS Manager:
- Click the server name at the top level (NOT a site)
- Double-click Application Request Routing Cache
- In the right panel, click Server Proxy Settings
- Check the box: Enable proxy
- Click Apply
Step 3: Deploy Application Files
3.1 Copy Files
Copy the entire shopfloor-dashboard folder to:
C:\inetpub\wwwroot\shopfloor-dashboard\
Files should include:
app.py(Flask application)requirements.txt(Python dependencies)web.config(IIS reverse proxy configuration)public\folder (index.html, logo, etc.)
3.2 Install Python Dependencies
cd C:\inetpub\wwwroot\shopfloor-dashboard
pip install -r requirements.txt
This installs:
- Flask
- mysql-connector-python
3.3 Configure Database Connection
Edit app.py lines 14-18:
DB_CONFIG = {
'host': 'localhost', # Your MySQL server
'port': 3306,
'user': '570005354', # Your MySQL username
'password': '570005354', # Your MySQL password
'database': 'shopdb'
}
Step 4: Test Flask Manually
Before setting up the service, test Flask works:
cd C:\inetpub\wwwroot\shopfloor-dashboard
python app.py
You should see:
Shopfloor Dashboard running on port 3001
Access at: http://localhost:3001
DEBUG MODE: DISABLED
Database: localhost:3306/shopdb
Test in browser or curl:
curl http://localhost:3001/health
curl http://localhost:3001/api/notifications
Both should return JSON responses (not errors).
Press Ctrl+C to stop.
Step 5: Install Flask as Windows Service (NSSM)
5.1 Download NSSM
- Download: https://nssm.cc/download
- Extract to
C:\nssm\
5.2 Install Service
REM Open Command Prompt as Administrator
cd C:\nssm\win64
REM Install service
nssm install ShopfloorDashboard "C:\Python312\python.exe" "app.py"
Note: Adjust Python path if different. Find with: where python
5.3 Configure Service
REM Set working directory
nssm set ShopfloorDashboard AppDirectory "C:\inetpub\wwwroot\shopfloor-dashboard"
REM Set display name
nssm set ShopfloorDashboard DisplayName "Shopfloor Dashboard (Flask)"
REM Set description
nssm set ShopfloorDashboard Description "GE Aerospace Shopfloor Events Dashboard - Flask Backend"
REM Set to start automatically
nssm set ShopfloorDashboard Start SERVICE_AUTO_START
REM Set environment variables (optional - defaults work)
nssm set ShopfloorDashboard AppEnvironmentExtra PORT=3001
REM Configure logging
nssm set ShopfloorDashboard AppStdout "C:\inetpub\wwwroot\shopfloor-dashboard\stdout.log"
nssm set ShopfloorDashboard AppStderr "C:\inetpub\wwwroot\shopfloor-dashboard\stderr.log"
REM Start service
nssm start ShopfloorDashboard
REM Verify status
nssm status ShopfloorDashboard
Should show: SERVICE_RUNNING
5.4 Verify Flask Service
REM Test Flask is responding
curl http://localhost:3001/health
REM Should return: {"status":"ok","timestamp":"..."}
If not working, check logs:
type "C:\inetpub\wwwroot\shopfloor-dashboard\stderr.log"
Step 6: Configure IIS Site
6.1 Create or Configure Site
In IIS Manager:
- Right-click Sites → Add Website (or use existing site)
- Configure:
- Site name: ShopfloorDashboard
- Physical path:
C:\inetpub\wwwroot\shopfloor-dashboard - Binding:
- Type: https
- Port: 443
- Host name: tsgwp00525.rd.ds.ge.com
- SSL Certificate: (select your cert)
6.2 Verify web.config
Ensure web.config exists in site root with reverse proxy rules.
The file should contain:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Reverse Proxy to Flask" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3001/{R:1}" />
</rule>
</rules>
</rewrite>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
6.3 Restart IIS Site
REM Restart specific site
iisreset /restart
REM Or in IIS Manager: Right-click site → Manage Website → Restart
Step 7: Test End-to-End
7.1 Test from Server
REM Test health check
curl https://tsgwp00525.rd.ds.ge.com/health
REM Test API
curl https://tsgwp00525.rd.ds.ge.com/api/notifications
7.2 Test from Browser
Open browser on any computer:
https://tsgwp00525.rd.ds.ge.com
Should show the dashboard with:
- GE Aerospace logo
- Clock
- Current and upcoming events
Troubleshooting
Issue 1: IIS Returns 500.31 Error
Cause: Flask service not running
Fix:
nssm status ShopfloorDashboard
nssm start ShopfloorDashboard
Issue 2: IIS Returns 502 Bad Gateway
Cause: Flask is running but IIS can't reach it
Fix:
REM Test Flask directly
curl http://localhost:3001/health
REM If Flask works, check ARR proxy is enabled
REM IIS Manager → Server → ARR → Server Proxy Settings → Enable proxy
Issue 3: API Returns Empty Data
Cause: Database connection issue
Fix:
REM Enable debug mode
nssm stop ShopfloorDashboard
set DEBUG=true
python app.py
REM Watch console for database errors
Issue 4: Changes Not Appearing
Fix:
REM Restart Flask service
nssm restart ShopfloorDashboard
REM Clear browser cache
Ctrl+Shift+R
Issue 5: Service Won't Start
Check logs:
type "C:\inetpub\wwwroot\shopfloor-dashboard\stderr.log"
Common causes:
- Python not in PATH
- Missing dependencies:
pip install -r requirements.txt - Database unreachable
- Port 3001 already in use
Maintenance Commands
Service Management
REM Start service
nssm start ShopfloorDashboard
REM Stop service
nssm stop ShopfloorDashboard
REM Restart service
nssm restart ShopfloorDashboard
REM Check status
nssm status ShopfloorDashboard
REM View service configuration
nssm get ShopfloorDashboard AppDirectory
nssm get ShopfloorDashboard AppEnvironmentExtra
REM Uninstall service
nssm stop ShopfloorDashboard
nssm remove ShopfloorDashboard confirm
View Logs
REM Flask stdout (normal messages)
type "C:\inetpub\wwwroot\shopfloor-dashboard\stdout.log"
REM Flask stderr (error messages)
type "C:\inetpub\wwwroot\shopfloor-dashboard\stderr.log"
REM IIS logs (requests)
type "C:\inetpub\logs\LogFiles\W3SVC1\*.log"
REM Windows Event Viewer (service events)
eventvwr.msc → Windows Logs → Application
Update Application
REM 1. Stop service
nssm stop ShopfloorDashboard
REM 2. Update files
REM Copy new files to C:\inetpub\wwwroot\shopfloor-dashboard\
REM 3. Update dependencies (if needed)
cd C:\inetpub\wwwroot\shopfloor-dashboard
pip install -r requirements.txt --upgrade
REM 4. Start service
nssm start ShopfloorDashboard
Security Considerations
Database Credentials
Option 1: Environment Variables (Recommended)
nssm set ShopfloorDashboard AppEnvironmentExtra DB_HOST=mysql-server DB_USER=user DB_PASS=password DB_NAME=shopdb
Option 2: Edit app.py
Not recommended for production - credentials in code.
Firewall
REM Flask only listens on localhost:3001 - no firewall rules needed
REM IIS handles public HTTPS on port 443
SSL Certificate
Ensure valid SSL certificate installed in IIS for HTTPS.
Monitoring
Check Service Health
REM Quick health check
curl http://localhost:3001/health
REM Check from external
curl https://tsgwp00525.rd.ds.ge.com/health
Monitor Logs
REM Watch Flask logs in real-time
powershell Get-Content -Path "C:\inetpub\wwwroot\shopfloor-dashboard\stderr.log" -Wait
Windows Task Scheduler
Create scheduled task to verify service is running every 5 minutes:
schtasks /create /tn "Check Shopfloor Dashboard" /tr "nssm status ShopfloorDashboard" /sc minute /mo 5
Performance Tuning
For Production Workloads
Consider using Gunicorn or Waitress instead of Flask's built-in server:
REM Install Waitress (pure Python, Windows-friendly)
pip install waitress
REM Create app_production.py:
from waitress import serve
from app import app
if __name__ == '__main__':
print('Shopfloor Dashboard (Waitress) running on port 3001')
serve(app, host='0.0.0.0', port=3001, threads=4)
REM Update NSSM service
nssm set ShopfloorDashboard AppParameters "app_production.py"
nssm restart ShopfloorDashboard
Backup and Disaster Recovery
Files to Backup
app.py(application code)web.config(IIS configuration)requirements.txt(dependencies)public/folder (frontend files)- NSSM service configuration
Export NSSM Configuration
REM Export service settings to registry file
reg export "HKLM\SYSTEM\CurrentControlSet\Services\ShopfloorDashboard" shopfloor-service-backup.reg
Quick Restore
REM 1. Copy files back to C:\inetpub\wwwroot\shopfloor-dashboard\
REM 2. Import registry (if service deleted)
reg import shopfloor-service-backup.reg
REM 3. Start service
nssm start ShopfloorDashboard
Support
View this guide:
C:\inetpub\wwwroot\shopfloor-dashboard\DEPLOYMENT_IIS_PROXY.md
Common Issues: See Troubleshooting section above
Logs: Check stderr.log and stdout.log files
Summary
✅ IIS handles HTTPS and public access ✅ Flask runs as Windows service on localhost:3001 ✅ URL Rewrite proxies requests to Flask ✅ MySQL database for notifications ✅ Auto-starts on server boot ✅ Logs to files for troubleshooting
Access: https://tsgwp00525.rd.ds.ge.com
Service: ShopfloorDashboard
Files: C:\inetpub\wwwroot\shopfloor-dashboard\