Spin up server with NGINX hosted website
Instructions
- Create Digital Ocean Droplet with the most basic settings.
- Enable the firewall "Firewall" for the newly created droplet
- Run slg-digital-ocean-droplet-setup -r 192.168.1.1 -u steven -dn on your local machine
- Once thats done, ssh to the remote server with ssh steven@192.168.1.1
- Install NGINX with slg-install-nginx.
If you are on something other than Ubuntu 20.04 then you will need to slg-install-nginx -h
to see what parameters need to be changed. The options available to you are listed. There may be more
codename's available than listed if a later version of Ubuntu/Debian comes out.
- Once that script has run, ensure it has been installed properly by visiting 192.168.1.1 in the browser
- Install firewall with slg-install-firewall
- Run slg-init-remote-crontab -u steven to add PATH extension to crontab
- Make sure you pointed your domain name to your new IP. Run sudo -E env "PATH=$PATH" slg-setup-tls-ssl-nginx example.com -u steven to setup HTTPS for the domain
- Run this to make your conf file act as a reverse proxy and use HTTP/2 sudo -E env "PATH=$PATH" slg-init-nginx-conf-gunicorn -f /etc/nginx/conf.d/project.conf -d example.com,www.example.com
- Run sudo mkdir -p /var/www/html/static to make the directory where nginx will serve static files from
- If you need to obfuscate the javascript, install obfuscator with sudo npm install -g javascript-obfuscator
- Run detached mongo docker instance with sudo docker run -p 27017:27017 -v /home/steven/project-mongo:/data/db -d mongo
The next commands relate to pulling projects from github and things to keep in mind
- Pull project and remember to recurse submodules git clone --recurse-submodules git@github.com:username/project.git
- Optionally create a virtual environment and then pip3 install -r requirements.txt
- Update any config files for production values
- Do any npm installs in related frontend (or backend) directories
- Also, remember to run any initialization scripts and set up any cron jobs.
Example: TwitchClip site which didn't have any streamer clips to retrieve
- Run server with gunicorn --bind 127.0.0.1:5000 -w 1 wsgi:app
- When you are at a desired place:
Ctrl-C to kill gunicorn then
Run gunicorn as a daemon gunicorn --bind 127.0.0.1:5000 -w 1 wsgi:app --daemon
10. Create repository from github boilerplate
11. Update nginx server configuration for the site to point to the gunicorn instance
12. Create gunicorn socke
13. Build github action that, upon pushes to master branch, pushes
Create a Firewall with a list of IP's
requests.post(
'https://api.digitalocean.com/v2/firewalls/',
headers={
"Authorization": "Bearer $DIGITALOCEAN_TOKEN",
"Content-Type": "application/json"
},
data=json.dumps({
"name":"Firewall",
"inbound_rules":[
{
"protocol":"tcp",
"ports":"22",
"sources": {"addresses": gh_action_ips[:900] }
},
{
"protocol":"tcp",
"ports":"22",
"sources": {"addresses": gh_action_ips[900:1800] }
},
{
"protocol":"tcp",
"ports":"22",
"sources": {"addresses": gh_action_ips[1800:] }
},
]})
)