Skip to content

Commit 8a2996f

Browse files
author
Jamie Curnow
committed
Split out docs, better error handling when database config doesn't exist
1 parent e1c3848 commit 8a2996f

File tree

10 files changed

+219
-77
lines changed

10 files changed

+219
-77
lines changed

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ RUN curl -L -o /tmp/s6-overlay-amd64.tar.gz "https://github.com/just-containers/
1919
# App
2020
ENV NODE_ENV=production
2121

22-
ADD dist /srv/app/dist
23-
ADD node_modules /srv/app/node_modules
24-
ADD src/backend /srv/app/src/backend
25-
ADD package.json /srv/app/package.json
26-
ADD knexfile.js /srv/app/knexfile.js
22+
ADD dist /app/dist
23+
ADD node_modules /app/node_modules
24+
ADD src/backend /app/src/backend
25+
ADD package.json /app/package.json
26+
ADD knexfile.js /app/knexfile.js
2727

2828
# Volumes
2929
VOLUME [ "/data", "/etc/letsencrypt" ]

Dockerfile.armhf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ RUN curl -L -o /tmp/s6-overlay-armhf.tar.gz "https://github.com/just-containers/
1919
# App
2020
ENV NODE_ENV=production
2121

22-
ADD dist /srv/app/dist
23-
ADD node_modules /srv/app/node_modules
24-
ADD src/backend /srv/app/src/backend
25-
ADD package.json /srv/app/package.json
26-
ADD knexfile.js /srv/app/knexfile.js
22+
ADD dist /app/dist
23+
ADD node_modules /app/node_modules
24+
ADD src/backend /app/src/backend
25+
ADD package.json /app/package.json
26+
ADD knexfile.js /app/knexfile.js
2727

2828
# Volumes
2929
VOLUME [ "/data", "/etc/letsencrypt" ]

README.md

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,17 @@ running at home or otherwise, including free SSL, without having to know too muc
1919

2020
## Getting started
2121

22-
### Method 1: Using docker-compose
23-
24-
By far the easiest way to get up and running. Create this `docker-compose.yml`
25-
26-
```yml
27-
version: "2"
28-
services:
29-
app:
30-
image: jc21/nginx-proxy-manager:preview
31-
ports:
32-
- 80:80
33-
- 81:81
34-
- 443:443
35-
volumes:
36-
- ./data:/data
37-
- ./letsencrypt:/etc/letsencrypt
38-
```
39-
40-
Then:
22+
Please consult the [installation instructions](doc/INSTALL.md) for a complete guide or
23+
if you just want to get up and running in the quickest time possible, grab all the files in the `doc/example/` folder and run `docker-compose up -d`
4124

42-
```bash
43-
docker-compose up -d
44-
```
45-
46-
47-
### Method 2: Using vanilla docker
48-
49-
```bash
50-
docker run -d \
51-
-p 80:80 \
52-
-p 81:81 \
53-
-p 443:443 \
54-
-v /path/to/data:/data \
55-
-v /path/to/letsencrypt:/etc/letsencrypt \
56-
jc21/nginx-proxy-manager
57-
```
5825

5926

6027
## Administration
6128

62-
Now that your docker container is running, connect to it on port `81` for the admin interface.
29+
When your docker container is running, connect to it on port `81` for the admin interface.
6330

6431
[http://localhost:81](http://localhost:81)
6532

66-
From here, the rest should be self explanatory.
67-
6833
Note: Requesting SSL Certificates won't work until this project is accessible from the outside world, as explained below.
6934

7035

@@ -75,6 +40,8 @@ Email: [email protected]
7540
Password: changeme
7641
```
7742

43+
Immediately after logging in with this default user you will be asked to modify your details and change your password.
44+
7845

7946
## Hosting your home network
8047

config/default.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"database": {
3-
"engine": "mysql",
4-
"host": "db",
5-
"name": "npm",
6-
"user": "npm",
7-
"password": "npm",
8-
"port": 3306
9-
}
2+
"database": {
3+
"engine": "mysql",
4+
"host": "db",
5+
"name": "npm",
6+
"user": "npm",
7+
"password": "npm",
8+
"port": 3306
9+
}
1010
}

doc/INSTALL.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
## Installation and Configuration
2+
3+
There's a few ways to configure this app depending on:
4+
5+
- Whether you use `docker-compose` or vanilla docker
6+
- Which Database you want to use (mysql or postgres)
7+
- Which architecture you're running it on (raspberry pi also supported)
8+
9+
### Configuration File
10+
11+
**The configuration file needs to be provided by you!**
12+
13+
Don't worry, this is easy to do.
14+
15+
The app requires a configuration file to let it know what database you're using and where it is.
16+
17+
Here's an example configuration for `mysql`:
18+
19+
```json
20+
{
21+
"database": {
22+
"engine": "mysql",
23+
"host": "127.0.0.1",
24+
"name": "nginxproxymanager",
25+
"user": "nginxproxymanager",
26+
"password": "password123",
27+
"port": 3306
28+
}
29+
}
30+
```
31+
32+
and here's one for `postgres`:
33+
34+
```json
35+
{
36+
"database": {
37+
"engine": "pg",
38+
"version": "7.2",
39+
"host": "127.0.0.1",
40+
"name": "nginxproxymanager",
41+
"user": "nginxproxymanager",
42+
"password": "password123",
43+
"port": 5432
44+
}
45+
}
46+
```
47+
48+
Once you've created your configuration file it's easy to mount it in the docker container, examples below.
49+
50+
**Note:** After the first run of the application, the config file will be altered to include generated encryption keys unique to your installation. These keys
51+
affect the login and session management of the application. If these keys change for any reason, all users will be logged out.
52+
53+
54+
### Database
55+
56+
This app doesn't come with a database, you have to provide one yourself. Currently `mysql` and `postgres` databases are supported.
57+
58+
It's easy to use another docker container for your database also and link it as part of the docker stack. Here's an example:
59+
60+
```yml
61+
version: "3"
62+
services:
63+
app:
64+
image: jc21/nginx-proxy-manager:2
65+
restart: always
66+
network_mode: host
67+
volumes:
68+
- ./config.json:/app/config/production.json
69+
- ./data:/data
70+
- ./letsencrypt:/etc/letsencrypt
71+
depends_on:
72+
- db
73+
db:
74+
image: mariadb
75+
restart: always
76+
environment:
77+
MYSQL_ROOT_PASSWORD: "password123"
78+
MYSQL_DATABASE: "nginxproxymanager"
79+
MYSQL_USER: "nginxproxymanager"
80+
MYSQL_PASSWORD: "password123"
81+
volumes:
82+
- ./data/mysql:/var/lib/mysql
83+
```
84+
85+
86+
### Running the App
87+
88+
Via `docker-compose`:
89+
90+
```yml
91+
version: "3"
92+
services:
93+
app:
94+
image: jc21/nginx-proxy-manager:2
95+
restart: always
96+
network_mode: host
97+
volumes:
98+
- ./config.json:/app/config/production.json
99+
- ./data:/data
100+
- ./letsencrypt:/etc/letsencrypt
101+
```
102+
103+
Vanilla Docker:
104+
105+
```bash
106+
docker run -d \
107+
--name nginx-proxy-manager \
108+
--network host \
109+
-v /path/to/config.json:/app/config/production.json \
110+
-v /path/to/data:/data \
111+
-v /path/to/letsencrypt:/etc/letsencrypt \
112+
jc21/nginx-proxy-manager:2
113+
```
114+
115+
116+
### Running on Raspberry PI / `armhf`
117+
118+
I have created a `armhf` docker container just for you. There may be issues with it,
119+
if you have issues please report them here.
120+
121+
```bash
122+
# Postgres:
123+
docker run -d \
124+
--name nginx-proxy-manager-db \
125+
--network host \
126+
-e POSTGRES_DB=nginxproxymanager \
127+
-e POSTGRES_USER=nginxproxymanager \
128+
-e POSTGRES_PASSWORD=password123 \
129+
-v /path/to/postgresql:/var/lib/postgresql/data \
130+
zsoltm/postgresql-armhf
131+
132+
# NPM:
133+
docker run -d \
134+
--name nginx-proxy-manager-app \
135+
--network host \
136+
-v /path/to/config.json:/app/config/production.json \
137+
-v /path/to/data:/data \
138+
-v /path/to/letsencrypt:/etc/letsencrypt \
139+
jc21/nginx-proxy-manager:2-armhf
140+
```

doc/example/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"database": {
3+
"engine": "mysql",
4+
"host": "db",
5+
"name": "nginxproxymanager",
6+
"user": "nginxproxymanager",
7+
"password": "password123",
8+
"port": 3306
9+
}
10+
}

doc/example/docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3"
2+
services:
3+
app:
4+
image: jc21/nginx-proxy-manager:2
5+
restart: always
6+
network_mode: host
7+
volumes:
8+
- ./config.json:/app/config/production.json
9+
- ./data:/data
10+
- ./letsencrypt:/etc/letsencrypt
11+
depends_on:
12+
- db
13+
db:
14+
image: mariadb
15+
restart: always
16+
environment:
17+
MYSQL_ROOT_PASSWORD: "password123"
18+
MYSQL_DATABASE: "nginxproxymanager"
19+
MYSQL_USER: "nginxproxymanager"
20+
MYSQL_PASSWORD: "password123"
21+
volumes:
22+
- ./data/mysql:/var/lib/mysql

rootfs/etc/services.d/manager/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
mkdir -p /data/letsencrypt-acme-challenge
44

55
cd /srv/app
6-
node --abort_on_uncaught_exception --max_old_space_size=250 /srv/app/src/backend/index.js
6+
node --abort_on_uncaught_exception --max_old_space_size=250 /app/src/backend/index.js

src/backend/db.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

3-
let config = require('config');
3+
const config = require('config');
44

55
if (!config.has('database')) {
6-
throw new Error('Database config does not exist! Read the README for instructions.');
6+
throw new Error('Database config does not exist! Please read the instructions: https://github.com/jc21/nginx-proxy-manager/blob/master/doc/INSTALL.md');
77
}
88

9-
let knex = require('knex')({
9+
let data = {
1010
client: config.database.engine,
1111
connection: {
1212
host: config.database.host,
@@ -18,6 +18,10 @@ let knex = require('knex')({
1818
migrations: {
1919
tableName: 'migrations'
2020
}
21-
});
21+
};
2222

23-
module.exports = knex;
23+
if (typeof config.database.version !== 'undefined') {
24+
data.version = config.database.version;
25+
}
26+
27+
module.exports = require('knex')(data);

src/backend/index.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
'use strict';
44

5-
const config = require('config');
6-
const app = require('./app');
7-
const logger = require('./logger').global;
8-
const migrate = require('./migrate');
9-
const setup = require('./setup');
10-
const apiValidator = require('./lib/validator/api');
11-
12-
let port = process.env.PORT || 81;
13-
14-
if (config.has('port')) {
15-
port = config.get('port');
16-
}
5+
const logger = require('./logger').global;
176

187
function appStart () {
8+
const migrate = require('./migrate');
9+
const setup = require('./setup');
10+
const app = require('./app');
11+
const apiValidator = require('./lib/validator/api');
12+
1913
return migrate.latest()
2014
.then(() => {
2115
return setup();
@@ -24,8 +18,8 @@ function appStart () {
2418
return apiValidator.loadSchemas;
2519
})
2620
.then(() => {
27-
const server = app.listen(port, () => {
28-
logger.info('PID ' + process.pid + ' listening on port ' + port + ' ...');
21+
const server = app.listen(81, () => {
22+
logger.info('PID ' + process.pid + ' listening on port 81 ...');
2923

3024
process.on('SIGTERM', () => {
3125
logger.info('PID ' + process.pid + ' received SIGTERM');
@@ -42,4 +36,9 @@ function appStart () {
4236
});
4337
}
4438

45-
appStart();
39+
try {
40+
appStart();
41+
} catch (err) {
42+
logger.error(err.message);
43+
process.exit(1);
44+
}

0 commit comments

Comments
 (0)