Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Nginx setup #9180

Draft
wants to merge 29 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b6b3ba6
Draft mkcert pr
DanielBelmes Oct 26, 2023
dc62860
fix configs
DanielBelmes Oct 30, 2023
9b51a35
Basic local nginx setup minus .env changes and host file changes(NOT …
DanielBelmes Oct 30, 2023
a6d0fdf
Merge branch 'dev' into mkcertCertificateCreation
DanielBelmes Oct 30, 2023
c24e2ef
fix again
DanielBelmes Oct 30, 2023
74d1ff9
Merge branch 'mkcertCertificateCreation' into nginxSetup
DanielBelmes Oct 31, 2023
bfae2c9
primus working
DanielBelmes Oct 31, 2023
c975f56
revert and rework
DanielBelmes Oct 31, 2023
b99dc1d
add generate-certs as optional script
DanielBelmes Oct 31, 2023
1cdb043
Merge branch 'mkcertCertificateCreation' into nginxSetup
DanielBelmes Oct 31, 2023
f67b48d
fix mac os
DanielBelmes Oct 31, 2023
ea906d1
Merge branch 'mkcertCertificateCreation' into nginxSetup
DanielBelmes Oct 31, 2023
abef525
updates
DanielBelmes Oct 31, 2023
45a0f56
Update docker-compose.yml
DanielBelmes Oct 31, 2023
c3327d5
Update docker-compose.yml
DanielBelmes Oct 31, 2023
8619673
mysql udp isn't needed. Forgot env var
DanielBelmes Nov 1, 2023
e3d6f0c
Add minio config
DanielBelmes Nov 2, 2023
ff77463
remove sql from nginx(not web content)
DanielBelmes Nov 2, 2023
e76f512
don't need to load balance udp/tcp
DanielBelmes Nov 2, 2023
c707e10
Merge branch 'dev' into mkcertCertificateCreation
DanielBelmes Nov 6, 2023
df45ed7
Merge branch 'mkcertCertificateCreation' into nginxSetup
DanielBelmes Nov 6, 2023
8b7f16b
Merge branch 'dev' into mkcertCertificateCreation
Nov 10, 2023
8d83b55
Merge branch 'mkcertCertificateCreation' into nginxSetup
Nov 10, 2023
aa14d94
start file server with npx
DanielBelmes Nov 12, 2023
c901419
Fix exiting of httpserver
DanielBelmes Nov 12, 2023
edac8af
Merge branch 'dev' into mkcertCertificateCreation
DanielBelmes Nov 12, 2023
22571e9
Merge branch 'mkcertCertificateCreation' into nginxSetup
DanielBelmes Nov 12, 2023
54fde20
Merge branch 'dev' into mkcertCertificateCreation
hanzlamateen Nov 15, 2023
1cf37c0
Merge branch 'mkcertCertificateCreation' into nginxSetup
DanielBelmes Nov 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .env.local.default
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ KEY=certs/key.pem


# Client variables ---------------
APP_TITLE=Ethereal Engine
APP_TITLE="Ethereal Engine"
APP_LOGO=https://etherealengine-static.s3-us-east-1.amazonaws.com/logo.png
APP_URL=https://localhost:3000
APP_HOST=localhost:3000
Expand Down Expand Up @@ -118,6 +118,8 @@ RTC_PORT_BLOCK_SIZE=50
INSTANCESERVER_PORT=3031
INSTANCESERVER_MODE=local
INSTANCESERVER_SHUTDOWN_DELAY_MS=30000
MEDIAINSTANCE_DOMAIN=local.etherealengine.com
MEDIAINSTANCE_PORT=3032
# --------------------------------

# Email variables ----------------
Expand All @@ -127,7 +129,7 @@ SMTP_SECURE=true
SMTP_USER=AKIARQM6EGKHDSORVC6Z
SMTP_PASS=
SMTP_FROM_NAME=noreply
SMTP_FROM_EMAIL=<ENTER_SENDER_EMAIL>
SMTP_FROM_EMAIL=ENTER_SENDER_EMAIL
# --------------------------------

# Authentication -----------------
Expand Down Expand Up @@ -216,3 +218,17 @@ NODE_ENV=production
OPENSEARCH_USER=admin
OPENSEARCH_PASSWORD=admin
OPENSEARCH_HOST=http://localhost:9200


# Ideally you should modify you /etc/hosts config to route local.etherealengine.com to localhost
# Make sure to run npm run dev-genereatecerts before hand
#NGINX OVERRIDES
#APP_URL=https://localhost
#APP_HOST=localhost
#CERT=certs/mkcert-cert.pem
#KEY=certs/mkcert-key.pem
#VITE_LOCAL_NGINX=true
#VITE_FILE_SERVER=https://localhost/fileserver/ or https://local.etherealengine.com/minio/
#VITE_TEST_FILE_SERVER=https://local.etherealengine.com/minio/etherealengine-static-resources-test
#LOCAL_STORAGE_PROVIDER=localhost
#REDIS_ENABLED=false
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,7 @@ project-package-jsons/*

feathers/*
/packages/ui/tests/jest-test-results.json
packages/ui/tests/jest-test-results.json
packages/ui/tests/jest-test-results.json

/certs/mkcert-cert.pem
/certs/mkcert-key.pem
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
"dev-docker-windows": "cd scripts && docker-compose up -d && docker-compose up -d -f docker-compose-minio.yml",
"dev-tabs": "cd scripts && ./dev-tabs.sh",
"fetch-projects": "lerna exec 'git fetch -p && git rebase' --parallel --ignore @etherealengine/*",
"dev-reinit": "npm run dev-docker && cd packages/server && npm run dev-reinit-db && cd ../../scripts && ./generate-certs.sh",
"dev-reinit": "npm run dev-docker && cd packages/server && npm run dev-reinit-db && cd ../../scripts",
"dev-server": "cd packages/server && npm run dev",
"dev-windows": "npm run dev-docker-windows && concurrently -n agones,server,client npm:dev-agones-silent npm:dev-server npm:dev-client",
"dev-debiancerts": "./generate-certs.sh",
"dev-gencerts": "cd ./scripts && ./generate-mkcerts.sh",
"diff": "lerna diff",
"format": "prettier --write \"packages/**/*.{ts,tsx}\" \"scripts/*.ts\"",
"format-scss": "stylelint \"packages/**/*.scss\" --fix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ export const connectToNetwork = async (
locationId,
channelId,
roomCode,
token
token,
server: 'instanceserver'
} as {
instanceID: InstanceID
locationId?: LocationID
Expand All @@ -259,10 +260,14 @@ export const connectToNetwork = async (
address?: string
port?: string
token: string
server: string
}

if (locationId) delete query.channelId
if (channelId) delete query.locationId
if (channelId) {
delete query.locationId
query.server = 'mediaserver'
}
if (!roomCode) delete query.roomCode

let primus: Primus
Expand Down
4 changes: 2 additions & 2 deletions packages/client/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ app.use(async (ctx) => {
app.listen = function () {
let server;
if (HTTPS) {
const key = readFileSync(join(packageRoot, 'certs/key.pem'))
const cert = readFileSync(join(packageRoot, 'certs/cert.pem'))
const key = readFileSync(join(packageRoot, process.env.key))
const cert = readFileSync(join(packageRoot, process.env.cert))
server = createServer({key: key, cert: cert }, this.callback());
} else {
server = _createServer(this.callback());
Expand Down
4 changes: 2 additions & 2 deletions packages/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ export default defineConfig(async () => {
...(isDevOrLocal
? {
https: {
key: fs.readFileSync(path.join(packageRoot.path, 'certs/key.pem')),
cert: fs.readFileSync(path.join(packageRoot.path, 'certs/cert.pem'))
key: fs.readFileSync(path.join(packageRoot.path, process.env.KEY ?? 'certs/key.pem')),
cert: fs.readFileSync(path.join(packageRoot.path, process.env.CERT ?? 'certs/cert.pem'))
}
}
: {})
Expand Down
2 changes: 2 additions & 0 deletions packages/server-core/src/appconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ const instanceserver = {
domain: process.env.INSTANCESERVER_DOMAIN || 'instanceserver.etherealengine.com',
releaseName: process.env.RELEASE_NAME || 'local',
port: process.env.INSTANCESERVER_PORT!,
mediaDomain: process.env.MEDIAINSTANCE_DOMAIN!,
mediaPort: process.env.MEDIAINSTANCE_PORT!,
locationName: process.env.PRELOAD_LOCATION_NAME!,
shutdownDelayMs: parseInt(process.env.INSTANCESERVER_SHUTDOWN_DELAY_MS!) || 0
}
Expand Down
4 changes: 2 additions & 2 deletions packages/server-core/src/createFileServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const serve = process.env.TEST === 'true' ? serveStatic('../server/upload_test/'

let server: https.Server = null!
const options = {
key: fs.readFileSync(join(packageRoot.path, 'certs/key.pem')),
cert: fs.readFileSync(join(packageRoot.path, 'certs/cert.pem'))
key: fs.readFileSync(join(packageRoot.path, process.env.KEY ?? 'certs/key.pem')),
cert: fs.readFileSync(join(packageRoot.path, process.env.CERT ?? 'certs/cert.pem'))
}

const createTestFileServer = (port: number, isServerRunning: boolean) => {
Expand Down
28 changes: 25 additions & 3 deletions packages/server-core/src/media/storageprovider/local.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { MULTIPART_CUTOFF_SIZE } from '@etherealengine/common/src/constants/File

import { FileBrowserContentType } from '@etherealengine/engine/src/schemas/media/file-browser.schema'
import { getState } from '@etherealengine/hyperflux'
import { ChildProcess } from 'child_process'
import logger from '../../ServerLogger'
import { ServerMode, ServerState } from '../../ServerState'
import config from '../../appconfig'
Expand Down Expand Up @@ -81,9 +82,30 @@ export class LocalStorage implements StorageProviderInterface {
this._store = fsStore(this.PATH_PREFIX)

if (getState(ServerState).serverMode === ServerMode.API && !config.testEnabled) {
require('child_process').spawn('npm', ['run', 'serve-local-files'], {
cwd: process.cwd(),
stdio: 'inherit'
const child: ChildProcess = require('child_process').spawn(
'npx',
[
'http-server',
`${this.PATH_PREFIX}`,
'--ssl',
'--cert',
`${config.server.certPath}`,
'--key',
`${config.server.keyPath}`,
'--port',
'8642',
'--cors=*',
'--brotli',
'--gzip'
],
{
cwd: process.cwd(),
stdio: 'inherit',
detached: true
}
)
process.on('exit', async () => {
process.kill(-child.pid!, 'SIGINT')
})
}
this.getOriginURLs().then((result) => (this.originURLs = result))
Expand Down
8 changes: 6 additions & 2 deletions packages/server-core/src/util/get-local-server-ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export interface ServerAddress {
export default async (isMediaInstance: boolean): Promise<ServerAddress> => {
const ip = configFile.instanceserver.domain === 'localhost' ? await internalIp.v4() : configFile.instanceserver.domain
return {
ipAddress: ip!,
port: isMediaInstance ? '3032' : '3031'
ipAddress: isMediaInstance ? configFile.instanceserver.mediaDomain : ip!,
port: process.env.VITE_LOCAL_NGINX
? '443'
: isMediaInstance
? configFile.instanceserver.mediaPort
: configFile.instanceserver.port
}
}
4 changes: 2 additions & 2 deletions packages/server/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export const start = async (): Promise<void> => {
let server
const HTTPS = process.env.VITE_LOCAL_BUILD ?? false
if (HTTPS) {
const key = fs.readFileSync(join(packageRoot.path, 'certs/key.pem'))
const cert = fs.readFileSync(join(packageRoot.path, 'certs/cert.pem'))
const key = fs.readFileSync(join(packageRoot.path, process.env.KEY ?? 'certs/key.pem'))
const cert = fs.readFileSync(join(packageRoot.path, process.env.CERT ?? 'certs/cert.pem'))
server = https.createServer({ key: key, cert: cert }, this.callback())
} else {
const http = require('http')
Expand Down
18 changes: 16 additions & 2 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

version: '2.3'
services:
db:
Expand Down Expand Up @@ -37,7 +36,22 @@ services:
command: redis-server
ports:
- '6379:6379'

# web:
# image: nginx
# container_name: etherealengine_nginx
# volumes:
# - ./nginx/templates:/etc/nginx/templates
# - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
# - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
# - ../certs:/etc/nginx/certs
# ports:
# - '80:80'
# - '443:443'
# environment:
# - NGINX_HOST
# - NGINX_PORT
# extra_hosts:
# - 'host.docker.internal:host-gateway'
# elasticsearch:
# image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
# container_name: elasticsearch
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ case "$(uname -s)" in
echo 'Not supported.'
echo 'Other OS'
;;
esac
esac
29 changes: 29 additions & 0 deletions scripts/generate-mkcerts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
if ! command -v -- "mkcert" > /dev/null 2>&1; then
echo "ERROR: mkcert not installed."
exit 1
fi
DIR=`pwd`/../certs
set -a; source ../.env.local; set +a
case "$(uname -s)" in
Darwin)
rm -f $DIR/mkcert-cert.pem
rm -f $DIR/mkcert-key.pem
mkcert -install
mkcert -cert-file $DIR/mkcert-cert.pem -key-file $DIR/mkcert-key.pem $VITE_APP_HOST
;;
Linux)
rm -f $DIR/mkcert-cert.pem
rm -f $DIR/mkcert-key.pem
mkcert -install
mkcert -cert-file $DIR/mkcert-cert.pem -key-file $DIR/mkcert-key.pem $VITE_APP_HOST
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
echo 'MS Windows'
echo "Automatic cert generation for SSL isn't supported on Windows, please add this code"
;;
*)
echo 'Not supported.'
echo 'Other OS'
;;
esac
Loading