Deploy a dotnet core site on nginx and systemd

This article is about how to deploy an ASP.Net core 3.1 site on nginx and systemd.

Preparation:

  • Prepare a server with nginx and systemd.
  • Install dotnet core support on server. Please check Microsoft site for details.
  • Build the binary files of the site to be deployed.

Step 1: Upload files

Make a folder in the server to be used to store site files. This folder will be marked as <SITEPATH> in all files below.

Upload your site files into this folder.

Give the permission to this folder.

sudo chown -R www-data:www-data <SITEPATH>
sudo chmod -R 755 <SITEPATH>

Step 2: Create systemd service

Create a service file. I suggest to put this file in the same folder of the site, aka <SITEPATH>. Let’s name it as myapp. You could change the name.
nano <SITEPATH>/myapp.service and enter this text below:

[Unit]
Description=<A_DESCRIPTION_TEXT_HERE>

[Service]
Environment=ASPNETCORE_URLS=http://localhost:<PORT_NUMBER>
Environment=ASPNETCORE_ENVIRONMENT=Production
WorkingDirectory=<SITEPATH>
ExecStart=/usr/bin/dotnet <SITEPATH>/<ENTRY_FILE>.dll
SyslogIdentifier=<A_NAME_HERE>
Restart=always
RestartSec=10
KillSignal=SIGINT
User=www-data

[Install]
WantedBy=multi-user.target

You should specify the description, port number, site path, entry file (main file), and the name to be used in syslog. Port number need to be different than all used by other services.

Link the file to systemd folder by ln -s <SITEPATH>/myapp.service /etc/systemd/system, reload systemd by systemctl daemon-reload, then start the service by systemctl start myapp.service. If everything goes will, you can see the port is listed in lsof -i -P -n | grep LISTEN. At last, set this service to start with system by systemctl enable myapp.service.

Step 3: Create nginx site.

Create the site file in sites-available folder by nano /etc/nginx/sites-available/<YOUR_SITE_NAME>, and enter this text below:

server {
    listen 80;
    listen [::]:80;
    server_name <SERVER_DOMAIN>;
    
    location / {
        proxy_pass http://localhost:<PORT_NUMBER>;
        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;
    }
}

You should specify the server domain name and the port number which is chosen for this app.

Link the file to enabled sites by ln -s /etc/nginx/sites-available/<YOUR_SITE_NAME> /etc/nginx/sites-enabled. Test config by nginx -t. If there is nothing wrong, apply the setting by systemctl reload nginx.

Further: Certbot

If you want to use certbot to apply a free ssl certificate to this site, the nginx plugin shipped with certbot can handle that without any problem. Use certbot with the nginx parameter to finish this job: certbot --nginx.

Fix Ubuntu Server bash for internet accessing (DNS querying)

I have multiple devices installed with Ubuntu Server. Some of them have a strange problem:
They can access internet using some applications, such as squid, without any problem.
They can ping to internet IP address.
They can use host / dig to query IP by domain name.
They cannot ping to internet by using domain name directly.
They cannot download file through wget / curl using domain name, but can do with IP.
They cannot use apt, stuck at connecting.
All they use a local dnsmasq as their dns.

After a long time dig, I found the problem and here is the fix.
open the file /etc/nsswitch.conf, search the line with “hosts:” and change the setting to “files dns” (without quotes).

Install ubuntu server into Soekris net6501 by using USB boot

This will guide you to prepare a installation media from Windows and install ubuntu into Soekris net6501.

Stuffs you need:

  • a USB stick that CAN BE RECOGNIZED by net6501 device.
    Not sure? Attach it to net6501 and reboot. If you can read the SIZE of this stick while booting, it is.
  • an ISO file for ubuntu server 32-bit. Version 16.10 is tested.
  • rufus. Guide and download point at https://www.ubuntu.com/download/desktop/create-a-usb-stick-on-windows.
  • a working serial connection from your workstation to your net6501, software included.

Prepare installation media:

  • Use rufus to build the USB stick. Check the guide above.

Install:

  1. Link net6501 to your computer using serial connection and start the link. In this case, I’m using the default setting (Speed=19200, Data bits=8, Stop bits=1, Parity=None, Flow control=XON/XOFF).
  2. Boot your net6501 with USB stick attached.
  3. Hit ctrl-p to go into bios.
  4. Type “boot 81” (without quotes) and press enter to boot from USB.
  5. You will see that something wrong with gfxboot.
  6. Type this text below SLOWLY and press enter. DO NOT COPY AND PASTE:
    install console=ttyS0,19200
  7. Do not press any key related to screen mode selection. It will be passed.
  8. Choose a language and continue installation steps as normal.

Finalize:

Grub configuration need to be adjusted for using serial as console.

Edit /etc/default/grub and change to these lines below:
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="console=ttyS0,19200 noplymouth"

Then run update-grub.

 

Hope this help you.

Show the System Information again in Ubuntu Server

Every time when I log on my ubuntu server, there always be a System Information displayed. How can we tell to the bash to re-display this screen again?

The command is: landscape-sysinfo

Simply, you just need to type land and press tab key to let the auto complete do the job.

 

Source: http://askubuntu.com/questions/7949/where-does-the-system-information-information-come-from-on-login