Configure HTTP Nginx
by John Vincent
Posted on May 12, 2018
This is part of a series of discussions regarding Deploying to a Digital Ocean Droplet.
For more details, please see Deploy TaskMuncher
Configure HTTP Nginx
Create HTTP configurations for
- www.taskmuncher.com
Configuration
Stop Nginx
sudo systemctl stop nginx
Remove default site
cd /etc/nginx/
sudo rm sites-enabled/default
sudo rm sites-available/default
Create directories for http and https configurations
cd /etc/nginx/sites-available
sudo mkdir http https
Configuration the domain
Create web server files
cd /var/www
sudo mkdir -p taskmuncher/html/.well-known
Note, the .well-known is for the SSL certs tasks.
For the domain, create file
* sudo vi /var/www/taskmuncher/html/index.html
<html>
<head>
<title>Welcome to {{DOMAIN-NAME}}com!</title>
</head>
<body>
<h1>Success! The {{DOMAIN-NAME}} server block is working!</h1>
</body>
</html>
Change the directory ownership
sudo chown -R jv:jv /var/www/taskmuncher/html
Change ownership of files
cd /var/www/taskmuncher/html
find . -type d -print0 | xargs -0 chmod 0755 # For directories
find . -type f -print0 | xargs -0 chmod 0644 # For files
Configure taskmuncher.com
sudo vi /etc/nginx/sites-available/http/taskmuncher
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name taskmuncher.com www.taskmuncher.com;
root /var/www/taskmuncher/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /.well-known {
allow all;
}
}
Scripts to Switch Http / Https
This is scripted as it is far too easy to get wrong.
Add 2 files to the bin directory
bin/enable-http
#!/bin/sh
#
# script to enable non-SSL
#
cd /etc/nginx/sites-enabled/
#
echo "Remove previous symbolic link"
sudo rm /etc/nginx/sites-enabled/taskmuncher
#
echo "Create symbolic links to HTTP files"
sudo ln -s /etc/nginx/sites-available/http/taskmuncher /etc/nginx/sites-enabled/taskmuncher
ls -la
#
echo "Restarting Pm2"
pm2 restart all
#
echo "Restarting Nginx"
sudo nginx -t
sudo systemctl restart nginx
#
echo "Completed"
bin/enable-https
#!/bin/sh
#
# script to enable SSL
#
cd /etc/nginx/sites-enabled/
#
echo "Remove previous symbolic link"
sudo rm /etc/nginx/sites-enabled/taskmuncher
#
echo "Create symbolic links to HTTPS files"
sudo ln -s /etc/nginx/sites-available/https/taskmuncher /etc/nginx/sites-enabled/taskmuncher
ls -la
#
echo "Checking for PM2 server.js task"
pm2 list
echo "If no tasks are listed, perform the following: "
echo "cd /var/www/taskmuncher/html"
echo "pm2 start server.js"
#
echo "Restarting PM2"
pm2 restart all
#
echo "Restarting Nginx"
sudo nginx -t
sudo systemctl restart nginx
#
echo "Mongo Status"
sudo systemctl status mongodb
#
echo "Completed"
Set permissions
chmod 744 enable-http*
Enable Http Server Blocks
Enable Http, also restarts Nginx
enable-http
Test from browser, now using port 80:
They all should be working.
http://www.taskmuncher.com
http://taskmuncher.com
Nginx
Taskmuncher
- Backup TaskMuncher from Digital Ocean
- Configure HTTP Nginx
- Configure HTTPS Nginx
- Configuring Google Domains
- Configuring Meta Tags
- Create Site Map
- Create SSL Certificates
- Create Ubuntu Droplet at Digital Ocean
- Deploy TaskMuncher React App to AWS
- Facebook Application Id
- First time deploy TaskMuncher React App to Digital Ocean
- Google Analytics for TaskMuncher
- Google Authentication
- Google Gmail Configuration
- Google Webmaster Tools
- Install Ubuntu Mongo
- Install Ubuntu Nginx
- Mailgun
- Maintaining Ubuntu Droplet
- Material-UI Showcase
- Optimizing TaskMuncher with Webpack 4
- React Production Issues
- TaskMuncher Images and Favicons
- TaskMuncher Overview
- TaskMuncher Performance
- TaskMuncher Website Validation
- Update SSL Certificates
- Update TaskMuncher for Lighthouse Findings
- Update TaskMuncher to be a Progressive Web App
- Update TaskMuncher to use React BrowserRouter
- Update TaskMuncher to Webpack v4, Babel v7, Material-UI v3
Ubuntu
- Configure HTTP Nginx
- Configure HTTP Nginx
- Configure HTTPS Nginx
- Configure HTTPS Nginx
- Configure PM2
- Create SSL Certificates
- Create SSL Certificates
- Create Ubuntu Droplet at Digital Ocean
- Create Ubuntu Droplet at Digital Ocean
- Deploy Feediator to Digital Ocean
- Install Jekyll Ubuntu
- Install Ubuntu Mongo
- Install Ubuntu Nginx
- Install Ubuntu Nginx
- Maintaining Ubuntu Droplet
- Maintaining Ubuntu Droplet
- SSH to Github
- Update SSL Certificates
- Update SSL Certificates