Home
Projects
Gear
Privacy
Contact Us
GitHub
Code
Our Github Repository
BBAI Backup Cam
Ghost Catcher Cam
Social Distance Desk Ornament
Ultrasonic Security Alarm
R2D2
Coke Drum IoT
Spider Man Web Slinger
Modbus Mega Logger
Ultimate Trike
Clock Crane
Jumbo Laser Etcher
Marshmallow-Rotisserie
Contact Us
ID:
Title:
Lead:
Signature:
<h2>INTRODUCTION</h2> <p>Running multiple web applications under your cable modem is virtually free and awesome. You can get domains for a couple of bucks, security certificates are free, and you can keep it all nested under a Virtual Box virtual machine to protect your home network. With today's single page app frameworks like via React or Blazor, the traffic is very low for a small business or a hobby. You won't even notice it while watching Netflix and your kids are streaming their games in the other room. </p> <h2>WORKFLOW</h2> <p>Here is how to install a web app. It is similar on a Windows machine, but this is a Linux example. You do step 3 and beyond for each domain you want to build.</p> <ol> <li>Buy a domain name: <a href="https://www.cloudns.net/premium/">Premium DNS hosting plans. Test for Free | ClouDNS</a></li> <li>Install the latest .Net. This example is for 7.0: </li> </ol> <pre class="language-markup"><code>wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb rm packages-microsoft-prod.deb sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-7.0</code></pre> <p style="padding-left: 20pt;">3. Make an example app with dotnet:</p> <pre class="language-markup"><code>dotnet new blazorserver -o myapp</code></pre> <p style="padding-left: 20pt;">4. Add your custom port to the application.json (the ports must be different for all your apps):</p> <pre class="language-markup"><code>"Kestrel": { "Endpoints": { "Https": { "Url": "http://127.0.0.1:5003" }, "Http": { "Url": "http://127.0.0.1:5002" } } }</code></pre> <p style="padding-left: 20pt;">5. Make the app run as a service by editing a service text file:</p> <pre class="language-markup"><code>#save this as /etc/systemd/system/kestrel-myapp.service [Unit] Description=myapp [Service] WorkingDirectory=/var/www/myapp ExecStart=dotnet /var/www/myapp/myapp.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=myapp User=root Environment=ASPNETCORE_ENVIRONMENT=Production [Install] WantedBy=multi-user.target</code></pre> <p style="padding-left: 20pt;"> </p> <p style="padding-left: 20pt;">6. Publish your app with dotnet. I write a script to do it for mine and simply execute the script. Here is my script that I name "m" and chmod +X to quickly publish:</p> <pre class="language-markup"><code>sudo systemctl stop kestrel-myapp sudo dotnet publish -o /var/www/myapp sudo systemctl start kestrel-myapp</code></pre> <p style="padding-left: 20pt;">7. Edit your Apache site config file:</p> <pre class="language-markup"><code># this is probably located under /etc/apache2/sites-enabled/000-default.conf <VirtualHost *:80> ServerName mysite.com ServerAlias www.mysite.com ProxyPreserveHost On ProxyPass / http://127.0.0.1:5002/ ProxyPassReverse / http://127.0.0.1:5002/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost></code></pre> <p style="padding-left: 20pt;">8. Get a free TSL (aka SSL) certificate from Let's Encrypt and Install it with Certbot. This will help somewhat: <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SSL-on-amazon-linux-2.html#letsencrypt">Tutorial: Configure SSL/TLS on Amazon Linux 2 - Amazon Elastic Compute Cloud.</a></p> <p style="padding-left: 20pt;"> </p> <h2>USEFUL COMMANDS</h2> <pre class="language-markup"><code>sudo systemctl restart apache2 #used after changing Virtual Host config files sudo journalctl -u kestrel-myapp.service #used to look at errors of your app service if it isn't working sudo systemctl status kestrel-myapp.service #used to see if your app service is running sudo systemctl daemon-reload #used after changing a service config file</code></pre> <p> </p> <h2>CONCLUSION</h2> <p>Seeing it all written out, it all makes perfect sense: 1) install the app framework, 2) run it as a service, 3) configure the web server to route traffic. However, having it written out will ensure you don't get so frustrated when you do it that you give up. I hope others find this helpful.</p> <p>-Sean</p>
View in New Tab
Copied! Use Ctrl-V to paste it back at your terminal.
Close