Forked from basharovV/https_nginx_express_node_config.md
Created
April 11, 2023 18:57
-
-
Save LitHaxor/8c725ede4a2768d32acd7809907a91a5 to your computer and use it in GitHub Desktop.
Revisions
-
basharovV revised this gist
Jul 19, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 1. Have a Node app ready for production. 2. Create an app.js file in your project directory: -
basharovV revised this gist
Jul 19, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
basharovV renamed this gist
Jul 19, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
basharovV revised this gist
Jul 19, 2017 . 2 changed files with 16 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,19 @@ 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 -
basharovV revised this gist
Jul 19, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ 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_http_version 1.1; } } -
basharovV revised this gist
Jul 19, 2017 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) 2. Configure Nginx at /etc/nginx/sites-available/default ``` @@ -40,4 +40,11 @@ server { } } ``` 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 ``` -
basharovV created this gist
Jul 19, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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)