maandag 4 november 2024

ssl certbot

uitleg voor installeren ssl certificaat via certbot:


 https://www.strato.nl/blog/lets-encrypt-gratis-ssl-certificaat-voor-servers/


https://certbot.eff.org/instructions?ws=nginx&os=pip


https://medium.com/@TechInWire/using-letsencrypt-to-secure-multiple-domains-with-nginx-95427c54be95

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

sudo certbot --nginx -d example.com -d www.example.com



woensdag 1 februari 2023

Large vhdx Docker

 The virtual harddrive of wsl for Docker can become very large when adding en removing containers.

As well as storing data like Mssql databases.

The file is located in your Appdata dictory of Docker %UserProfile%\AppData\Local\Docker\wsl\data\ext4.vhdx.

To cleanup the drive you can purge all unused images en containers in docker, but you can also shrink the file with Powershell.

The command Optimize-Vhd is used to shrink the file.

Optimize-Vhd -Path .\ext4.vhdx -Mode full

If you get an error when using this command, it's not available, then you'll have to install Hyper-V tools via Windows features.

Before you can run the Optimize command, you'll have to quit Docker Desktop

Check if there are running containers with 

wsl -l --running or wsl -l -v to show the details

if nothing is running you need to stop wsl, with wsl --shutdown.

Now you can run the Optimize-Vhd command.


Read more:

Scott hanselman's blog


Move the vhdx file to another drive:

wsl --shutdown
wsl --export docker-desktop-data docker-desktop-data.tar
wsl --unregister docker-desktop-data
wsl --import docker-desktop-data X:\path\to X:\path\to\docker-desktop-data.tar --version 2
ref: https://github.com/docker/for-win/issues/7348


dinsdag 25 oktober 2022

Check uptime linux en mysql

 Voor linux gebruik het commando

uptime


voor mysql:

gebruikt:

SELECT DATE_SUB(now(), INTERVAL variable_value SECOND) "LAST STARTUP" from performance_schema.global_status where variable_name='Uptime';


of in linux:

service mysql status

woensdag 17 augustus 2022

asp.net in linux

in asp.net 

add systemd support

var builder = WebApplication.CreateBuilder(args);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
    builder.Host.UseSystemd(); // for linux...
}


    <PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />

add forwarding for nginx

var app = builder.Build();

//for nginx
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

 

on ubuntu create a directory in:

/var/www/<appname>

build / publish asp.net project for linux

dotnet publish -c Release -r linux-x64 --no-self-contained

Check if .net runtime is installed if it does not work you can also use --self-contained in your build command

copy contents to directory

give permission to <appname> dir with command:

chmod 775 -R /var/www/<appname>

set execute rechten op exe file

chmod +x /var/www/<appname dir>/<appname> (without dll) in linux

Systemd

Create a service file in systemd

create an empty <appname>.service file (touch filename)

put in the following content (nano filename)

[Unit]

Description=app description

After=network.target


[Service]

WorkingDirectory=/var/www/uitgekookt-logistics-route-generation-api/current

ExecStart=/var/www/<appdir>/<linux generated file without extension / appname>

Restart=always

# Restart service after 10 seconds if the dotnet service crashes:

RestartSec=10

KillSignal=SIGINT

User=www-data

Environment=ASPNETCORE_ENVIRONMENT=Production

Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

Environment=AllowedHosts=*

Environment=ApplicationInsights__InstrumentationKey=

Environment=Connectionstrings__ABC=abc

Environment=ASPNETCORE_URLS=http://localhost:5040


Enable service:

sudo systemctl enable <appname>.service

Start

sudo systemctl start <appname>.service


NGINX

For nginx create an <appname> file in /etc/nginx/sites-available/ dir

with contents:

server {

    listen 50400; //external port

    listen [::]:50400; 

    location / {

        proxy_pass         http://127.0.0.1:5040; //portnumber of .net api

        proxy_http_version 1.1;

        proxy_set_header   Upgrade $http_upgrade;

        proxy_set_header   Connection keep-alive;

        proxy_set_header   Host $host;

        proxy_cache_bypass $http_upgrade;

        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header   X-Forwarded-Proto $scheme;

    }

}

create a systemlink from sites-available to sites-enabled:

ln -s /etc/nginx/sites-available/<appname> /etc/nginx/sites-enabled/<appname>

allow port 50400 in firewall (ufw enable)

reload nginx (nginx -s reload)

when there are issues with the application scan the log via:

sudo journalctl -fu <appname>.service


Meer info:

Host ASP.NET Core on Linux with Nginx | Microsoft Docs


vrijdag 24 juni 2022

install mysql on linux

 How To Install MySQL on Ubuntu 20.04 | DigitalOcean

check if mysql is running systemctl list-units --type=service --state=running or

systemctl --type=service

grant acces to user

open port in firewall for external communication


Run SQL file in MySQL database from terminal? (tutorialspoint.com)

woensdag 15 juni 2022

python - django - wagtail cms

install python 3.9

install pip for use in commandline:

download :get-pip.py

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
install pip:
python3 get-pip.py

see: https://www.geeksforgeeks.org/how-to-install-pip-in-macos

install wagtail; see https://wagtail.org/developers/


when modulenotfound exception use:

python -m pip install django
python -m pip install wagtail

dinsdag 14 juni 2022

static web app configuration

 place a staticwebapp.config.json file in the root of your application.

Configure Azure Static Web Apps | Microsoft Docs

fe:

{
  "navigationFallback": {
    "rewrite": "/index.html",
    "exclude": [
      "/assets/icons/*.{png,jpg,gif,webp}",
      "/assets/images/*.{png,jpg,gif,webp}",
      "/assets/*.{json}"
    ]
  },
  "mimeTypes": {
    ".json": "text/json",
    ".webp": "image/webp"
  },
  "routes": [
    {
      "route": "index.html",
      "headers": {
        "Cache-Control": "no-store"
      }
    }
  ]
}