Initial commit: Mobil_Tag project setup
This commit is contained in:
+139
@@ -0,0 +1,139 @@
|
||||
# Ubuntu-Server Setup für Mobile Tag
|
||||
|
||||
Diese Anleitung zeigt, wie du Node.js neben PHP auf einem Ubuntu-Server installierst und das Mobile Tag Backend betreibst.
|
||||
|
||||
## 1. Node.js installieren (Methode A: NodeSource)
|
||||
|
||||
```bash
|
||||
# System aktualisieren
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# NodeSource Repository für Node.js 20 hinzufügen
|
||||
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||
|
||||
# Node.js + npm installieren
|
||||
sudo apt-get install -y nodejs
|
||||
|
||||
# Version prüfen
|
||||
node -v
|
||||
npm -v
|
||||
```
|
||||
|
||||
## Alternative: Node.js mit nvm installieren (empfohlen)
|
||||
|
||||
```bash
|
||||
# nvm installieren
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
|
||||
|
||||
# nvm in aktueller Session verfügbar machen
|
||||
source ~/.bashrc
|
||||
|
||||
# Node.js 20 installieren
|
||||
nvm install 20
|
||||
nvm use 20
|
||||
nvm alias default 20
|
||||
|
||||
# Version prüfen
|
||||
node -v
|
||||
npm -v
|
||||
```
|
||||
|
||||
## 2. Projekt auf den Server kopieren
|
||||
|
||||
Per `git clone`, `scp`, `rsync` oder FTP in ein Verzeichnis wie `/var/www/mobile-tag` kopieren.
|
||||
|
||||
```bash
|
||||
cd /var/www/mobile-tag
|
||||
```
|
||||
|
||||
## 3. Abhängigkeiten installieren
|
||||
|
||||
```bash
|
||||
npm run install:all
|
||||
```
|
||||
|
||||
## 4. Build
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
## 5. Server starten
|
||||
|
||||
### Einfacher Start (für Tests)
|
||||
|
||||
```bash
|
||||
cd server
|
||||
npm start
|
||||
```
|
||||
|
||||
Der Server läuft dann auf Port `3001`.
|
||||
|
||||
### Produktiver Start mit PM2 (empfohlen)
|
||||
|
||||
```bash
|
||||
# PM2 global installieren
|
||||
sudo npm install -g pm2
|
||||
|
||||
# Server als Dienst starten
|
||||
cd /var/www/mobile-tag/server
|
||||
pm2 start dist/index.js --name mobile-tag-server
|
||||
|
||||
# PM2 so konfigurieren, dass es nach Neustart automatisch startet
|
||||
pm2 save
|
||||
pm2 startup
|
||||
# → Den ausgegebenen Befehl kopieren und ausführen
|
||||
```
|
||||
|
||||
## 6. Reverse Proxy mit Nginx (empfohlen)
|
||||
|
||||
Damit das Backend über HTTPS und Port 443 erreichbar ist, kannst du Nginx als Reverse Proxy nutzen:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name api.dein-domain.de;
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:3001;
|
||||
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;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Anschließend Let's Encrypt für HTTPS einrichten:
|
||||
|
||||
```bash
|
||||
sudo apt install certbot python3-certbot-nginx -y
|
||||
sudo certbot --nginx -d api.dein-domain.de
|
||||
```
|
||||
|
||||
## 7. Frontend deployen
|
||||
|
||||
Das Frontend (`client/dist` nach `npm run build`) kannst du wie gewohnt über deinen PHP-Webserver ausliefern.
|
||||
|
||||
Im Client muss die Server-URL angepasst werden (`client/.env`):
|
||||
|
||||
```bash
|
||||
VITE_SERVER_URL=https://api.dein-domain.de
|
||||
```
|
||||
|
||||
## 8. Firewall
|
||||
|
||||
Falls UFW aktiv ist, Port 3001 nur für den internen Reverse Proxy freigeben (oder für Tests direkt):
|
||||
|
||||
```bash
|
||||
sudo ufw allow 3001/tcp
|
||||
```
|
||||
|
||||
Bei Verwendung von Nginx Reverse Proxy ist das nicht nötig.
|
||||
|
||||
## Wichtige Hinweise
|
||||
|
||||
- Das Backend braucht **Node.js**, da PHP keine WebSocket-Verbindungen für Echtzeit-Spiele halten kann.
|
||||
- Dein PHP-Server kann weiterhin parallel laufen.
|
||||
- Für HTTPS ist Let's Encrypt empfohlen, da Kamera/GPS/Orientierung in Browsern HTTPS erfordern.
|
||||
Reference in New Issue
Block a user