Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save LitHaxor/8c725ede4a2768d32acd7809907a91a5 to your computer and use it in GitHub Desktop.

Select an option

Save LitHaxor/8c725ede4a2768d32acd7809907a91a5 to your computer and use it in GitHub Desktop.

Revisions

  1. @basharovV basharovV revised this gist Jul 19, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion https_nginx_express_node_config.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # How to configure HTTPS with Lets Encrypt, Nginx reverse proxy, Express and Node Raw
    # How to configure HTTPS with Lets Encrypt, Nginx reverse proxy, Express and Node

    1. Have a Node app ready for production.
    2. Create an app.js file in your project directory:
  2. @basharovV basharovV revised this gist Jul 19, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions https_nginx_express_node_config.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # How to configure HTTPS with Lets Encrypt, Nginx reverse proxy, Express and Node Raw

    1. Have a Node app ready for production.
    2. Create an app.js file in your project directory:
    ```javascript
  3. @basharovV basharovV renamed this gist Jul 19, 2017. 1 changed file with 0 additions and 0 deletions.
  4. @basharovV basharovV revised this gist Jul 19, 2017. 2 changed files with 16 additions and 13 deletions.
    12 changes: 0 additions & 12 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +0,0 @@
    const express = require('express');
    const path = require('path');
    const app = express();

    // Allow dotfiles - this is required for verification by Lets Encrypt's certbot
    app.use(express.static(path.join(__dirname, 'build'), {dotfiles: 'allow'}));

    app.get('*', function (req, res) {
    res.sendFile(path.join(__dirname, 'build', 'index.html'));
    });

    app.listen(3000);
    17 changes: 16 additions & 1 deletion https_nginx_config.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,19 @@
    1. Configure Express as per the app.js above
    1. Have a Node app ready for production.
    2. Create an app.js file in your project directory:
    ```javascript
    const express = require('express');
    const path = require('path');
    const app = express();

    // Allow dotfiles - this is required for verification by Lets Encrypt's certbot
    app.use(express.static(path.join(__dirname, 'build'), {dotfiles: 'allow'}));

    app.get('*', function (req, res) {
    res.sendFile(path.join(__dirname, 'build', 'index.html'));
    });

    app.listen(3000);
    ```
    2. [Follow this guide to get your SSL certificates](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
    2. Configure Nginx at /etc/nginx/sites-available/default

  5. @basharovV basharovV revised this gist Jul 19, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions https_nginx_config.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    1. [Follow this guide to get your SSL certificates](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
    1. Configure Express as per the app.js above
    2. [Follow this guide to get your SSL certificates](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
    2. Configure Nginx at /etc/nginx/sites-available/default

    ```
    @@ -35,7 +36,7 @@ server {
    # Allow location for Acme challenge - you also might need to allow 'dotfiles' in Express (see next section)
    location ~ /.well-known {
    allow all;
    proxy_pass http://127.0.0.1:3000;
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    }
    }
  6. @basharovV basharovV revised this gist Jul 19, 2017. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions https_nginx_config.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    1. [Follow this guide to get your SSL certificates:](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
    1. [Follow this guide to get your SSL certificates](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
    2. Configure Nginx at /etc/nginx/sites-available/default

    ```
    @@ -40,4 +40,11 @@ server {
    }
    }
    ```
    3. Configure Express as below (assuming you have a /build folder for production)
    3. Restart Nginx and start your Express server (I recommend PM2 to manage the process):
    ```
    sudo systemctl restart nginx
    ```
    In your project directory:
    ```
    pm2 start app.js
    ```
  7. @basharovV basharovV created this gist Jul 19, 2017.
    12 changes: 12 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    const express = require('express');
    const path = require('path');
    const app = express();

    // Allow dotfiles - this is required for verification by Lets Encrypt's certbot
    app.use(express.static(path.join(__dirname, 'build'), {dotfiles: 'allow'}));

    app.get('*', function (req, res) {
    res.sendFile(path.join(__dirname, 'build', 'index.html'));
    });

    app.listen(3000);
    43 changes: 43 additions & 0 deletions https_nginx_config.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    1. [Follow this guide to get your SSL certificates:](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04)
    2. Configure Nginx at /etc/nginx/sites-available/default

    ```
    # Default server configuration
    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com www.example.com;
    return 301 https://$server_name$request_uri;
    }
    # Virtual Host/SSL/Reverse proxy configuration for example.com
    server {
    # Listen on both HTTP and HTTPS - between Nginx and Express the traffic is HTTP but this is not a major
    # security concern as both services are on the same box
    listen 80;
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;
    server_name example.com www.example.com;
    location / {
    proxy_pass http://127.0.0.1:3000;
    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;
    }
    # Allow location for Acme challenge - you also might need to allow 'dotfiles' in Express (see next section)
    location ~ /.well-known {
    allow all;
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    }
    }
    ```
    3. Configure Express as below (assuming you have a /build folder for production)