Developing .net core app and deploying to linux at digital ocean
Materials you will need
- your own domain name already purchased. (suggest http://gandi.net as registrar)
- $5 per month to pay digital ocean
- need a local machine on which you will do your development. (i'll assume local machine is windows though it could easily be osx or linux)
With any articles mentioned below: be sure to read the comments. Sometimes they highlight common problems that people have, or shortcomings/errors in the article that haven't been corrected yet.
Prepare your digital ocean account
- sign up at digital ocean.
- use PuTTYgen to create SSH keypair
- tell digital ocean about your public key.
Create and configure your droplet
- Create a droplet at digital ocean. Must be 64 bit (.net core does not run in 32 bit linux). Would currently be Ubuntu 16.
- tell it to use the SSH key you already provided it with.
- use PuTTY to connect to your droplet as root
- create a new user
- give that user sudo privileges
- test that the new user can connect through SSH.
- test that the new user can use sudo privileges.
- stop the root user from being able to connect.
- install and configure fail2ban
- customize your bash profile (totally unnecessary, but fun!!)
- install .net core on your droplet
- build a helloworld console app
- test your helloworld console app
- install sftp
- create /opt/websites/ -- this is the folder where you will upload your web applications
- create a new user who will have limited privileges such as uploading files.
- give the new user permissions to read and write the /opt/websites/ area.
Prepare to publish to droplet (on your machine)
- use filezilla to connect to your droplet, as your file uploading user.
- verify that you can download/upload files
- create a new .net core app
- customize its port number. (this will be handy if you want to host more than 1 app in your droplet)
- publish it using
dotnet publish
(from the folder that contains theproject.json
file. The published content will end up in thebin\Debug\netcoreapp1.0\publish\
subfolder) - upload the published content to your droplet
Test via cli (on your droplet)
- install nginx
- configure nginx to act as a reverse proxy to your site
- run your site in a console. (dotnet
yoursite.dll
)
Tell via ip address (from a browser)
- visit your ipaddress... see that the site is returned
- configure nameservers at your domain name registrar
- setup domain records at digital ocean (a record, cname)
Make site reliable (on your droplet)
- configure nginx to expect the domain name
- install supervisor
- configure supervisor to keep your app running
Website monitoring
- use pingdom or "statuscake" to monitor your site(s).
Here was my preliminary list
STEP ONE: THE MUST-HAVES
- Review the Ubuntu 14.04 server checklist which covers:
- Initial Ubuntu server setup tutorial with step-by-step configuration instructions, and
- Connecting to your Droplet with SSH.
- Use DigitalOcean's DNS to set up your hostname from the Control Panel.
- Protect your servers by reviewing these 7 security measures.
- Keep your data safe with an effective backup strategy.
STEP TWO: WEB SERVERS
- Install the powerful Nginx web server on Ubuntu
- Use Nginx virtual hosts to serve multiple sites on one server.
EXTRA CREDIT: SECURE FILE TRANSFER
- Securely transfer files to your server and between droplets using SFTP.
Sources
- http://benfoster.io/blog/how-to-configure-kestrel-urls-in-aspnet-core-rc2
- install .net core on ubuntu
- How to set up a host name with digital ocean
- chmod
- .net core in production on linux (covers nginx, supervisord)
- How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 16.04
- How To Use Filezilla to Transfer and Manage Files Securely on your VPS
- How To Protect SSH with Fail2Ban on Ubuntu 14.04
- Initial Server Setup with Ubuntu 16.04
- Uncomplicated FireWall (ufw) on ubuntu
- Publishing an ASP.NET Core website to a cheap Linux VM host