> For the complete documentation index, see [llms.txt](https://hex-docs.gitbook.io/setup/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hex-docs.gitbook.io/setup/post-install/windows-server-setup.md).

# Windows Server Setup

## 1. Download Required Software

* Nginx: <http://nginx.org/en/download.html>
* MongoDB: <https://www.mongodb.com/try/download/community>
* OpenSSL: <https://slproweb.com/products/Win32OpenSSL.html>
* NSSM: <https://nssm.cc/download>
* Python: Microsoft Store or python.org

## 2. System Setup

mkdir C:\data\db mkdir C:\data\log mkdir C:\nginx

## 3. Environment Variables

## Add to System PATH:

C:\Program Files\MongoDB\Server\6.0\bin C:\nginx

## 4. MongoDB Configuration

## Create file: C:\Program Files\MongoDB\Server\6.0\mongod.cfg

storage: dbPath: C:\data\db security: authorization: enabled systemLog: destination: file path: C:\data\log\mongod.log net: bindIp: 127.0.0.1 port: 27017

## 5. Install MongoDB Service

mongod --config "C:\Program Files\MongoDB\Server\6.0\mongod.cfg" --install net start MongoDB

## 6. Nginx Configuration

## Create file: C:\nginx\conf\nginx.conf

worker\_processes auto; events { worker\_connections 1024; }

http { include mime.types; default\_type application/octet-stream; sendfile on; keepalive\_timeout 65;

```
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    location / {
        proxy_pass http://localhost:YOUR_APP_PORT;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
```

}

## 7. Install Nginx Service

nssm install nginx "C:\nginx\nginx.exe" nssm start nginx

## 8. SSL Setup

pip install certbot certbot-nginx certbot --nginx -d yourdomain.com -d [www.yourdomain.com](http://www.yourdomain.com)

## 9. MongoDB Security

mongosh use admin db.createUser({ user: "adminUser", pwd: "securePassword", roles: \[ { role: "userAdminAnyDatabase", db: "admin" } ] })

## 10. Windows Firewall Rules

netsh advfirewall firewall add rule name="HTTP" dir=in action=allow protocol=TCP localport=80 netsh advfirewall firewall add rule name="HTTPS" dir=in action=allow protocol=TCP localport=443 netsh advfirewall firewall add rule name="MongoDB" dir=in action=allow protocol=TCP localport=27017

## 11. Cloudflare Setup

1. Create account at cloudflare.com
2. Add domain
3. Update nameservers at registrar
4. Add A record → server IP
5. Set SSL/TLS to "Full"

## 12. Service Management Commands

net start MongoDB net stop MongoDB net start nginx net stop nginx nginx -t nginx -s reload

## 13. Log Locations

Nginx: C:\nginx\logs\access.log, C:\nginx\logs\error.log MongoDB: C:\data\log\mongod.log

## 14. Monitoring Setup

1. Open Event Viewer
2. Create Custom Views for:
   * MongoDB events
   * Nginx events
   * System errors
   * Security events

## 15. Backup Configuration

1. MongoDB Backup: mongodump --out C:\backup\mongodb$(date +%Y%m%d)
2. Configuration Backup: xcopy C:\nginx\conf C:\backup\nginx\conf /E /I /Y xcopy "C:\Program Files\MongoDB\Server\6.0\mongod.cfg" C:\backup\mongodb\ /Y

## 16. Security Measures

1. Windows Updates:
   * Settings → Update & Security
   * Enable automatic updates
2. Windows Defender:
   * Enable real-time protection
   * Run weekly full scans
3. User Access:
   * Create service accounts
   * Implement least privilege access

## 17. Performance Optimization

1. MongoDB:
   * Enable WiredTiger cache
   * Index optimization
   * Regular maintenance
2. Nginx:
   * Worker optimization
   * Gzip compression
   * Cache settings

## 18. Maintenance Schedule

Daily:

* Check logs
* Verify services
* Monitor disk space

Weekly:

* Full system backup
* Security updates
* Log rotation

Monthly:

* SSL certificate check
* Performance review
* Security audit

## 19. Troubleshooting Guide

Service Issues:

1. Check service status
2. Review event logs
3. Verify configurations
4. Check port availability

Connection Issues:

1. Test network connectivity
2. Verify firewall rules
3. Check DNS settings
4. Validate SSL certificates

Performance Issues:

1. Monitor resource usage
2. Check log files
3. Review configurations
4. Analyze system metrics

## 20. Emergency Procedures

Service Recovery:

1. Stop affected service
2. Check logs
3. Restore configuration
4. Start service
5. Verify functionality

Data Recovery:

1. Stop services
2. Restore from backup
3. Verify data integrity
4. Start services
5. Test functionality

Remember to:

* Replace placeholder values
* Keep secure password copies
* Document all custom changes
* Maintain backup schedule
* Monitor system regularly
