Skip to content

Instantly share code, notes, and snippets.

@nethoncho
Last active October 27, 2017 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nethoncho/59838383cb8f063143c6655529978623 to your computer and use it in GitHub Desktop.
Save nethoncho/59838383cb8f063143c6655529978623 to your computer and use it in GitHub Desktop.
Meteor nginx application proxy on Ubuntu 16.04.3 LTS
# Use sudo before each command if not logged in as root
#
# Install nginx https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04
apt-get update
apt-get install nginx
# Check that HTTP port 80 and HTTPS port 443 are open
ufw app status
# Make sure nginx starts on boot
systemctl enable nginx
# Install certbot https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-ngin
# Edit /etc/nginx/sites-available/default
# Find server_name _; and replace _; with your domain.
# server_name example.com www.example.com;
systemctl reload nginx
# Run certbot
# Note: the current version of certbot will setup cron for you so it will automatically renew your certificates
# Choose redirects from http to https when certbot asks
certbot --nginx -d example.com
systemctl reload nginx
# See the included example nginx config
# Now just start your meteor application with a non root user
# meteor defaults to port 3009
meteor run
# File /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
# Some options are not needed but left overs from the default install
root /var/www/html;
index index.html;
server_name example.com;
location / {
# proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
# configure websockets handling
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment