Fix admin route access and backend configuration
- Added /admin redirect to login page in nginx config - Fixed backend server.js route ordering for proper admin handling - Updated authentication middleware and routes - Added user management routes - Configured PostgreSQL integration - Updated environment configuration
This commit is contained in:
493
Sky_Art_shop/DEPLOYMENT_GUIDE.md
Normal file
493
Sky_Art_shop/DEPLOYMENT_GUIDE.md
Normal file
@@ -0,0 +1,493 @@
|
||||
# Sky Art Shop - Web Deployment Guide
|
||||
|
||||
**Target:** XAMPP v3.3.0 + No-IP Dynamic DNS
|
||||
**Date:** December 3, 2025
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Deployment Overview
|
||||
|
||||
This guide will help you deploy your ASP.NET Core application to the web so clients can view it while you continue development locally.
|
||||
|
||||
### Architecture
|
||||
|
||||
```
|
||||
Internet → No-IP DNS → Your Public IP → Router Port Forward → XAMPP/IIS → ASP.NET Core App
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Important Notes
|
||||
|
||||
1. **XAMPP Limitation**: XAMPP is primarily for PHP applications. For ASP.NET Core, we'll use **IIS (Internet Information Services)** or **Kestrel** as a Windows Service.
|
||||
2. **No-IP**: Your dynamic DNS will point to your public IP address
|
||||
3. **Port Forwarding**: You'll need to forward ports 80 (HTTP) and 443 (HTTPS) on your router
|
||||
4. **Security**: This setup is for preview purposes. For production, use a proper hosting service.
|
||||
|
||||
---
|
||||
|
||||
## 📋 Prerequisites
|
||||
|
||||
- ✅ Windows 10/11 with IIS or Windows Server
|
||||
- ✅ .NET 8.0 Runtime installed
|
||||
- ✅ MongoDB running on localhost:27017
|
||||
- ✅ No-IP account configured with your hostname
|
||||
- ✅ Router access for port forwarding
|
||||
- ✅ Static local IP for your server machine
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Option 1: Deploy with IIS (Recommended)
|
||||
|
||||
### Step 1: Enable IIS on Windows
|
||||
|
||||
1. Open **Control Panel** → **Programs** → **Turn Windows features on or off**
|
||||
2. Check these features:
|
||||
- ✅ Internet Information Services
|
||||
- ✅ Web Management Tools
|
||||
- ✅ World Wide Web Services
|
||||
- ✅ Application Development Features
|
||||
- ✅ .NET Extensibility 4.8
|
||||
- ✅ ASP.NET 4.8
|
||||
- ✅ IIS Management Console
|
||||
3. Click **OK** and wait for installation
|
||||
|
||||
### Step 2: Install ASP.NET Core Hosting Bundle
|
||||
|
||||
1. Download from: <https://dotnet.microsoft.com/download/dotnet/8.0>
|
||||
2. Look for "Hosting Bundle" (includes .NET Runtime and IIS support)
|
||||
3. Install and restart your computer
|
||||
|
||||
### Step 3: Publish Your Application
|
||||
|
||||
Run these commands in PowerShell:
|
||||
|
||||
```powershell
|
||||
cd "E:\Documents\Website Projects\Sky_Art_Shop"
|
||||
dotnet publish SkyArtShop.csproj -c Release -o "C:\inetpub\wwwroot\skyartshop"
|
||||
```
|
||||
|
||||
**Note:** Make sure to run each command separately, pressing Enter after each one.
|
||||
|
||||
### Step 4: Configure Application Settings for Production
|
||||
|
||||
Create production settings:
|
||||
|
||||
```powershell
|
||||
# Copy appsettings.json to production version
|
||||
Copy-Item "appsettings.json" "C:\inetpub\wwwroot\skyartshop\appsettings.Production.json"
|
||||
```
|
||||
|
||||
### Step 5: Create IIS Site
|
||||
|
||||
1. Open **IIS Manager** (search in Windows Start)
|
||||
2. Expand your server name → Right-click **Sites** → **Add Website**
|
||||
3. Configure:
|
||||
- **Site name**: SkyArtShop
|
||||
- **Physical path**: `C:\inetpub\wwwroot\skyartshop`
|
||||
- **Binding**:
|
||||
- Type: http
|
||||
- IP: All Unassigned
|
||||
- Port: 80
|
||||
- Host name: (leave empty or add your No-IP hostname)
|
||||
4. Click **OK**
|
||||
|
||||
### Step 6: Configure Application Pool
|
||||
|
||||
1. In IIS Manager, click **Application Pools**
|
||||
2. Find **SkyArtShop** pool → Right-click → **Basic Settings**
|
||||
3. Set **.NET CLR version**: **No Managed Code**
|
||||
4. Click **OK**
|
||||
5. Right-click pool → **Advanced Settings**
|
||||
6. Set **Start Mode**: **AlwaysRunning**
|
||||
7. Set **Identity**: **ApplicationPoolIdentity** or your user account
|
||||
8. Click **OK**
|
||||
|
||||
### Step 7: Set Permissions
|
||||
|
||||
```powershell
|
||||
# Grant IIS permissions to your application folder
|
||||
icacls "C:\inetpub\wwwroot\skyartshop" /grant "IIS_IUSRS:(OI)(CI)F" /T
|
||||
icacls "C:\inetpub\wwwroot\skyartshop" /grant "IUSR:(OI)(CI)F" /T
|
||||
|
||||
# Grant permissions to uploads folder
|
||||
icacls "C:\inetpub\wwwroot\skyartshop\wwwroot\uploads" /grant "IIS_IUSRS:(OI)(CI)F" /T
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Option 2: Deploy as Windows Service with Kestrel
|
||||
|
||||
### Step 1: Publish Application
|
||||
|
||||
```powershell
|
||||
cd "E:\Documents\Website Projects\Sky_Art_Shop"
|
||||
dotnet publish SkyArtShop.csproj -c Release -o "C:\Services\SkyArtShop"
|
||||
```
|
||||
|
||||
### Step 2: Install as Windows Service
|
||||
|
||||
```powershell
|
||||
# Install the service using sc.exe command
|
||||
sc.exe create SkyArtShopService binPath="C:\Services\SkyArtShop\SkyArtShop.exe" start=auto
|
||||
|
||||
# Or use NSSM (Non-Sucking Service Manager) - Download from nssm.cc
|
||||
# Download from: https://nssm.cc/download
|
||||
nssm install SkyArtShopService "C:\Services\SkyArtShop\SkyArtShop.exe"
|
||||
```
|
||||
|
||||
### Step 3: Configure Service
|
||||
|
||||
```powershell
|
||||
# Set service to start automatically
|
||||
sc.exe config SkyArtShopService start=auto
|
||||
|
||||
# Start the service
|
||||
sc.exe start SkyArtShopService
|
||||
|
||||
# Check service status
|
||||
sc.exe query SkyArtShopService
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🌐 Network Configuration
|
||||
|
||||
### Step 1: Set Static Local IP
|
||||
|
||||
1. Open **Control Panel** → **Network and Sharing Center**
|
||||
2. Click your network connection → **Properties**
|
||||
3. Select **Internet Protocol Version 4 (TCP/IPv4)** → **Properties**
|
||||
4. Choose **Use the following IP address**:
|
||||
- IP: `192.168.1.100` (or similar, check your router's range)
|
||||
- Subnet: `255.255.255.0`
|
||||
- Gateway: Your router IP (usually `192.168.1.1`)
|
||||
- DNS: `8.8.8.8` (Google DNS)
|
||||
|
||||
### Step 2: Configure Router Port Forwarding
|
||||
|
||||
1. Access your router admin panel (usually <http://192.168.1.1>)
|
||||
2. Find **Port Forwarding** or **Virtual Server** settings
|
||||
3. Add new rule:
|
||||
- **Service Name**: SkyArtShop-HTTP
|
||||
- **External Port**: 80
|
||||
- **Internal IP**: 192.168.1.100 (your server's static IP)
|
||||
- **Internal Port**: 80
|
||||
- **Protocol**: TCP
|
||||
4. Add HTTPS rule (optional):
|
||||
- **Service Name**: SkyArtShop-HTTPS
|
||||
- **External Port**: 443
|
||||
- **Internal IP**: 192.168.1.100
|
||||
- **Internal Port**: 443
|
||||
- **Protocol**: TCP
|
||||
5. Save settings
|
||||
|
||||
### Step 3: Configure Windows Firewall
|
||||
|
||||
```powershell
|
||||
# Allow HTTP traffic
|
||||
New-NetFirewallRule -DisplayName "SkyArtShop-HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
|
||||
|
||||
# Allow HTTPS traffic (optional)
|
||||
New-NetFirewallRule -DisplayName "SkyArtShop-HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
|
||||
|
||||
# Or allow the application itself
|
||||
New-NetFirewallRule -DisplayName "SkyArtShop-App" -Direction Inbound -Program "C:\inetpub\wwwroot\skyartshop\SkyArtShop.exe" -Action Allow
|
||||
```
|
||||
|
||||
### Step 4: Update No-IP Configuration
|
||||
|
||||
1. Log in to your No-IP account (<https://www.noip.com>)
|
||||
2. Go to **Dynamic DNS** → **Hostnames**
|
||||
3. Your hostname (e.g., `yoursite.ddns.net`) should already be configured
|
||||
4. Install **No-IP DUC (Dynamic Update Client)** to keep your IP updated:
|
||||
- Download from: <https://www.noip.com/download>
|
||||
- Install and configure with your No-IP credentials
|
||||
- It will automatically update your DNS when your public IP changes
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Update Application Configuration
|
||||
|
||||
### 1. Update appsettings.Production.json
|
||||
|
||||
```json
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"MongoDB": {
|
||||
"ConnectionString": "mongodb://localhost:27017",
|
||||
"DatabaseName": "SkyArtShopDB"
|
||||
},
|
||||
"AdminUser": {
|
||||
"Email": "admin@skyartshop.com",
|
||||
"Password": "Admin123!",
|
||||
"Name": "Sky Art Shop Admin"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Update Program.cs for Production URLs
|
||||
|
||||
The app should listen on all interfaces in production. This is already configured in your Program.cs:
|
||||
|
||||
```csharp
|
||||
builder.WebHost.UseUrls("http://localhost:5001");
|
||||
```
|
||||
|
||||
Change to:
|
||||
|
||||
```csharp
|
||||
// Allow configuration from environment or use default
|
||||
if (builder.Environment.IsProduction())
|
||||
{
|
||||
builder.WebHost.UseUrls("http://*:80", "https://*:443");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.WebHost.UseUrls("http://localhost:5001");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Security Considerations
|
||||
|
||||
### 1. Change Admin Password
|
||||
|
||||
Update `appsettings.Production.json` with a strong password:
|
||||
|
||||
```json
|
||||
"AdminUser": {
|
||||
"Email": "admin@skyartshop.com",
|
||||
"Password": "YourStrongPassword123!@#",
|
||||
"Name": "Sky Art Shop Admin"
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Configure HTTPS (Recommended)
|
||||
|
||||
For HTTPS, you'll need an SSL certificate:
|
||||
|
||||
**Option A: Free SSL with Let's Encrypt**
|
||||
|
||||
1. Use **Certify The Web** (free for IIS): <https://certifytheweb.com>
|
||||
2. Install and configure with your No-IP domain
|
||||
3. It will automatically obtain and renew certificates
|
||||
|
||||
**Option B: Self-Signed Certificate (for testing)**
|
||||
|
||||
```powershell
|
||||
# Create self-signed certificate
|
||||
New-SelfSignedCertificate -DnsName "yoursite.ddns.net" -CertStoreLocation "cert:\LocalMachine\My"
|
||||
```
|
||||
|
||||
### 3. Disable Development Features
|
||||
|
||||
Ensure `ASPNETCORE_ENVIRONMENT` is set to `Production`:
|
||||
|
||||
```powershell
|
||||
# For IIS (web.config)
|
||||
# This is automatically set when you publish with -c Release
|
||||
|
||||
# For Windows Service
|
||||
[Environment]::SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Production", "Machine")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📁 File Structure After Deployment
|
||||
|
||||
```
|
||||
C:\inetpub\wwwroot\skyartshop\ (or C:\Services\SkyArtShop\)
|
||||
├── SkyArtShop.exe
|
||||
├── SkyArtShop.dll
|
||||
├── appsettings.json
|
||||
├── appsettings.Production.json
|
||||
├── web.config (auto-generated for IIS)
|
||||
├── wwwroot\
|
||||
│ ├── assets\
|
||||
│ ├── uploads\
|
||||
│ └── ...
|
||||
└── ... (other dependencies)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Testing Your Deployment
|
||||
|
||||
### Local Testing (on server machine)
|
||||
|
||||
1. Open browser on server
|
||||
2. Navigate to: `http://localhost` or `http://127.0.0.1`
|
||||
3. You should see your site
|
||||
|
||||
### Network Testing (from another device on same network)
|
||||
|
||||
1. Find your server's local IP: `192.168.1.100`
|
||||
2. On another device (phone/laptop on same WiFi)
|
||||
3. Navigate to: `http://192.168.1.100`
|
||||
|
||||
### Internet Testing (from outside your network)
|
||||
|
||||
1. Use your No-IP hostname: `http://yoursite.ddns.net`
|
||||
2. Test from mobile data or ask a friend to visit
|
||||
3. Should load your site from the internet
|
||||
|
||||
### Troubleshooting Commands
|
||||
|
||||
```powershell
|
||||
# Check if port 80 is listening
|
||||
netstat -ano | findstr :80
|
||||
|
||||
# Check IIS site status
|
||||
Get-WebSite -Name "SkyArtShop"
|
||||
|
||||
# Check Windows Service status
|
||||
Get-Service -Name "SkyArtShopService"
|
||||
|
||||
# View application logs
|
||||
Get-EventLog -LogName Application -Source "IIS*" -Newest 20
|
||||
|
||||
# Test if MongoDB is accessible
|
||||
Test-NetConnection -ComputerName localhost -Port 27017
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔄 Updating Your Site (While Keeping it Live)
|
||||
|
||||
When you want to update the site:
|
||||
|
||||
### Method 1: Quick Update (IIS)
|
||||
|
||||
```powershell
|
||||
# 1. Stop IIS site
|
||||
Stop-WebSite -Name "SkyArtShop"
|
||||
|
||||
# 2. Publish new version
|
||||
cd "E:\Documents\Website Projects\Sky_Art_Shop"
|
||||
dotnet publish SkyArtShop.csproj -c Release -o "C:\inetpub\wwwroot\skyartshop"
|
||||
|
||||
# 3. Start IIS site
|
||||
Start-WebSite -Name "SkyArtShop"
|
||||
```
|
||||
|
||||
### Method 2: Zero-Downtime Update
|
||||
|
||||
```powershell
|
||||
# 1. Publish to new folder
|
||||
dotnet publish SkyArtShop.csproj -c Release -o "C:\inetpub\wwwroot\skyartshop_new"
|
||||
|
||||
# 2. Stop site
|
||||
Stop-WebSite -Name "SkyArtShop"
|
||||
|
||||
# 3. Backup old version
|
||||
Rename-Item "C:\inetpub\wwwroot\skyartshop" "skyartshop_backup"
|
||||
|
||||
# 4. Switch to new version
|
||||
Rename-Item "C:\inetpub\wwwroot\skyartshop_new" "skyartshop"
|
||||
|
||||
# 5. Start site
|
||||
Start-WebSite -Name "SkyArtShop"
|
||||
|
||||
# 6. Test and remove backup if successful
|
||||
# Remove-Item "C:\inetpub\wwwroot\skyartshop_backup" -Recurse
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 Monitoring
|
||||
|
||||
### Check Application Status
|
||||
|
||||
```powershell
|
||||
# IIS
|
||||
Get-WebSite -Name "SkyArtShop" | Select-Object Name, State, PhysicalPath
|
||||
|
||||
# Windows Service
|
||||
Get-Service -Name "SkyArtShopService" | Select-Object Name, Status, StartType
|
||||
```
|
||||
|
||||
### View Logs
|
||||
|
||||
Logs location:
|
||||
|
||||
- **IIS**: `C:\inetpub\wwwroot\skyartshop\logs\` (if configured)
|
||||
- **Windows Event Viewer**: Application logs
|
||||
- **MongoDB**: Check MongoDB logs for database issues
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Quick Deployment Checklist
|
||||
|
||||
- [ ] .NET 8.0 Hosting Bundle installed
|
||||
- [ ] IIS enabled and configured
|
||||
- [ ] Application published to IIS folder
|
||||
- [ ] Application pool configured (No Managed Code)
|
||||
- [ ] Folder permissions set (IIS_IUSRS)
|
||||
- [ ] Static local IP configured
|
||||
- [ ] Router port forwarding setup (port 80)
|
||||
- [ ] Windows Firewall rules added
|
||||
- [ ] No-IP DUC client installed and running
|
||||
- [ ] MongoDB running on localhost
|
||||
- [ ] Production settings configured
|
||||
- [ ] Admin password changed
|
||||
- [ ] Site tested locally
|
||||
- [ ] Site tested from local network
|
||||
- [ ] Site tested from internet (No-IP hostname)
|
||||
|
||||
---
|
||||
|
||||
## 🆘 Common Issues & Solutions
|
||||
|
||||
### Issue 1: HTTP Error 502.5
|
||||
|
||||
**Cause**: ASP.NET Core Runtime not installed
|
||||
**Solution**: Install .NET 8.0 Hosting Bundle
|
||||
|
||||
### Issue 2: Site Not Accessible from Internet
|
||||
|
||||
**Cause**: Port forwarding not configured
|
||||
**Solution**: Check router settings, ensure port 80 is forwarded to correct local IP
|
||||
|
||||
### Issue 3: 403 Forbidden Error
|
||||
|
||||
**Cause**: Permissions issue
|
||||
**Solution**: Run the icacls commands to grant IIS permissions
|
||||
|
||||
### Issue 4: MongoDB Connection Failed
|
||||
|
||||
**Cause**: MongoDB not running
|
||||
**Solution**: Start MongoDB service: `net start MongoDB`
|
||||
|
||||
### Issue 5: No-IP Hostname Not Resolving
|
||||
|
||||
**Cause**: No-IP DUC not running or IP not updated
|
||||
**Solution**: Install/restart No-IP DUC client
|
||||
|
||||
---
|
||||
|
||||
## 📞 Support Resources
|
||||
|
||||
- **IIS Documentation**: <https://docs.microsoft.com/en-us/iis>
|
||||
- **ASP.NET Core Hosting**: <https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/>
|
||||
- **No-IP Support**: <https://www.noip.com/support>
|
||||
- **Let's Encrypt**: <https://letsencrypt.org>
|
||||
|
||||
---
|
||||
|
||||
## 🎉 Success
|
||||
|
||||
Once deployed, your site will be accessible at:
|
||||
|
||||
- **Local**: <http://localhost>
|
||||
- **Network**: <http://192.168.1.100> (your local IP)
|
||||
- **Internet**: <http://yoursite.ddns.net> (your No-IP hostname)
|
||||
|
||||
Clients can view the site while you continue development locally on port 5001! 🚀
|
||||
Reference in New Issue
Block a user