浏览代码

first commit | nginx configs | compose files | ssl scripts

cia-freehand
TOJ 7 年前
当前提交
b5bd912e0b

+ 24
- 0
README.md 查看文件

@@ -0,0 +1,24 @@
1
+### Production Container Helpers
2
+
3
+Nginx container
4
+
5
+Nodejs Application container
6
+
7
+
8
+Nginx serves the application as a reverse proxy.
9
+
10
+host-machine:8001 -> nginx:80 -> nodejs:3001
11
+
12
+
13
+#### Usage
14
+Change the configuration files labelled <CHANGE ME> with your domain
15
+
16
+Start containers: docker-compose up
17
+
18
+Stop and remove containers: ./kill_production.sh
19
+
20
+Generate new keys with certbot:
21
+    -Check using `sudo certbot renew --dry-run`
22
+    -Run the commands inside the `generatekeys.sh`
23
+    -DO NOT run `generatekeys.sh` as a script
24
+    -Run the `./rebuild.sh` script to use the new keys

+ 12
- 0
docker-compose.yml 查看文件

@@ -0,0 +1,12 @@
1
+version: '3'
2
+
3
+services:
4
+    nginx:
5
+        build:
6
+            context: .
7
+            dockerfile: ./nginx/Dockerfile
8
+        image: proxy-nginx
9
+        ports:
10
+            - "80:80"
11
+            - "443:443"
12
+        restart: always

+ 7
- 0
kill_production.sh 查看文件

@@ -0,0 +1,7 @@
1
+#!/bin/sh
2
+
3
+### Stops and removes the nginx proxy
4
+docker stop production_nginx_1 && docker rm production_nginx_1
5
+
6
+### Stops and removes the nodejs app container
7
+# docker stop production_nodejs_1 && docker rm production_nodejs_1

+ 21
- 0
nginx/Dockerfile 查看文件

@@ -0,0 +1,21 @@
1
+FROM nginx
2
+
3
+### Copy files from the temp build
4
+COPY ./nginx/temp/index.html /opt/<CHANGE_ME>/public/index.html
5
+
6
+### Setup SSL
7
+RUN mkdir -p /etc/ssl/private && chmod 700 /etc/ssl/private
8
+RUN mkdir -p /etc/ssl/certs && chmod 700 /etc/ssl/certs
9
+
10
+### Copy the SSL Certificate and Key
11
+COPY ./nginx/keys/letsencrypt.key /etc/ssl/private/letsencrypt.key
12
+COPY ./nginx/keys/letsencrypt.crt /etc/ssl/certs/letsencrypt.crt
13
+
14
+### Configure Nginx to Use SSL
15
+RUN mkdir -p /etc/nginx/snippets
16
+COPY ./nginx/configs/letsencrypt.conf /etc/nginx/snippets/letsencrypt.conf
17
+COPY ./nginx/configs/ssl-params.conf /etc/nginx/snippets/ssl-params.conf
18
+
19
+### Move over the nginx.conf and default.config server configs
20
+COPY ./nginx/configs/default.conf /etc/nginx/conf.d/default.conf
21
+COPY ./nginx/configs/nginx.conf /etc/nginx/nginx.conf

+ 63
- 0
nginx/configs/default.conf 查看文件

@@ -0,0 +1,63 @@
1
+# Upstream sites for proxy-ing
2
+upstream wp {
3
+     server <CHANGE_ME>:8082;
4
+}
5
+
6
+### Redirect regular traffic to SSL
7
+server {
8
+    listen 80 default_server;
9
+    listen [::]:80 default_server;
10
+
11
+    server_name <CHANGE_ME> www.<CHANGE_ME>;
12
+
13
+    # return 301 https://$host$request_uri;
14
+
15
+    # root /opt/app/public/;
16
+    # WP Test
17
+    root /var/www/html;
18
+    index index.html index.htm index.php index.nginx-debian.html;
19
+
20
+    location / {
21
+        proxy_set_header    Host                 $host;
22
+        proxy_set_header    X-Real-IP            $remote_addr;
23
+        proxy_set_header    X-Forwarded-For      $proxy_add_x_forwarded_for;
24
+        proxy_set_header    X-Forwarded-Proto    $scheme;
25
+
26
+        proxy_pass          http://wp;
27
+        proxy_redirect      off;
28
+    }
29
+}
30
+
31
+### SSL Stuff
32
+server {
33
+    listen 443 ssl http2;
34
+    listen [::]:443 ssl http2;
35
+
36
+    server_name <CHANGE_ME> www.<CHANGE_ME>;
37
+
38
+    include snippets/letsencrypt.conf;
39
+    include snippets/ssl-params.conf;
40
+
41
+    root /var/www/html;
42
+    index index.html index.htm index.php index.nginx-debian.html;
43
+
44
+    # location / {
45
+    #    try_files $uri $uri/ /index.php;
46
+    # }
47
+
48
+    location / {
49
+        proxy_set_header        Host              $host;
50
+        proxy_set_header        X-Real-IP         $remote_addr;
51
+        proxy_set_header        X-Forwarded-For   $proxy_add_x_forwarded_for;
52
+        proxy_set_header        X-Forwarded-Proto $scheme;
53
+        proxy_set_header        Accept-Encoding   "";
54
+        proxy_set_header        Proxy             "";
55
+
56
+        proxy_pass          http://wp;
57
+        proxy_redirect      off;
58
+    }
59
+
60
+    location ~/\.ht {
61
+        deny all;
62
+    }
63
+}

+ 2
- 0
nginx/configs/letsencrypt.conf 查看文件

@@ -0,0 +1,2 @@
1
+ssl_certificate /etc/ssl/certs/letsencrypt.crt;
2
+ssl_certificate_key /etc/ssl/private/letsencrypt.key;

+ 32
- 0
nginx/configs/nginx.conf 查看文件

@@ -0,0 +1,32 @@
1
+user  nginx;
2
+worker_processes  4;
3
+
4
+error_log  /var/log/nginx/error.log warn;
5
+pid        /var/run/nginx.pid;
6
+
7
+
8
+events {
9
+    worker_connections  1024;
10
+}
11
+
12
+
13
+http {
14
+    include       /etc/nginx/mime.types;
15
+    default_type  application/octet-stream;
16
+
17
+    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
18
+                      '$status $body_bytes_sent "$http_referer" '
19
+                      '"$http_user_agent" "$http_x_forwarded_for"';
20
+
21
+    access_log  /var/log/nginx/access.log  main;
22
+
23
+    sendfile        on;
24
+    #tcp_nopush     on;
25
+
26
+    keepalive_timeout  65;
27
+
28
+    #gzip  on;
29
+
30
+    # Bring over default server config
31
+    include /etc/nginx/conf.d/default.conf;
32
+}

+ 21
- 0
nginx/configs/ssl-params.conf 查看文件

@@ -0,0 +1,21 @@
1
+# from https://cipherli.st/
2
+# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
3
+
4
+ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
5
+ssl_prefer_server_ciphers on;
6
+ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
7
+ssl_ecdh_curve secp384r1;
8
+ssl_session_cache shared:SSL:10m;
9
+ssl_session_tickets off;
10
+ssl_stapling on;
11
+ssl_stapling_verify on;
12
+resolver 8.8.8.8 8.8.4.4 valid=300s;
13
+resolver_timeout 5s;
14
+# Disable preloading HSTS for now.  You can use the commented out header line that includes
15
+# the "preload" directive if you understand the implications.
16
+#add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
17
+add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
18
+add_header X-Frame-Options DENY;
19
+add_header X-Content-Type-Options nosniff;
20
+
21
+# ssl_dhparam /etc/ssl/certs/dhparam.pem;

+ 11
- 0
nginx/temp/index.html 查看文件

@@ -0,0 +1,11 @@
1
+<html>
2
+
3
+<head>
4
+    <title>Test Page</title>
5
+</head>
6
+
7
+<body>
8
+    <p>temp nginx folder</p>
9
+</body>
10
+
11
+</html>

+ 2
- 0
rebuild_production.sh 查看文件

@@ -0,0 +1,2 @@
1
+#!/bin/sh
2
+docker-compose build --no-cache && docker-compose up

+ 18
- 0
renew_keys.sh 查看文件

@@ -0,0 +1,18 @@
1
+#!/bin/bash
2
+
3
+docker stop production_nginx_1
4
+
5
+### Get new keys
6
+sudo certbot renew
7
+
8
+### Remove the old keys
9
+rm ~/production/nginx/keys/letsencrypt/old/letsencrypt.*
10
+
11
+### Deprecate and back up the current keys
12
+mv ~/production/nginx/keys/letsencrypt.* ~/production/nginx/keys/old
13
+
14
+### Copy over the new keys
15
+sudo cat /etc/letsencrypt/live/<CHANGE_ME>/fullchain.pem > ~/production/nginx/keys/letsencrypt.crt
16
+sudo cat /etc/letsencrypt/live/<CHANGE_ME>/privkey.pem > ~/production/nginx/keys/letsencrypt.key
17
+
18
+echo "RUN the ./rebuild.sh script now to move over the newly generated keys and restart the container"

正在加载...
取消
保存