Host a aspnet core webpage on a directadmin environment with pm2

What is it? questionmark

Hosting some aspnet core webpages, it made me realize that I never documented any of the actions needed to set it up.
My servers run Debian with DirectAdmin, configured with apache and nginx.

This post will show how my TimelapseMP4Webpage is published to https://vwp.timdows.com/timelapse.

Configuring DirectAdmin as a user

Adding the domain name under the user

Make it nice and more secure with an SSL certificate from Let’s Encrypt

Upload the aspnet core webpage to a users directory

For this, I use Visual Studio Code’s build in task manager and created the following two tasks:

{
	"label": "Publish webpage",
	"type": "shell",
	"command": "dotnet publish --runtime debian-x64",
	"group": "test",
	"presentation": {
		"reveal": "always",
		"panel": "new"
	}
},
{
	"label": "Upload published webpage",
	"type": "shell",
	"command": "./.vscode/upload.ps1",
	"group": "test",
	"presentation": {
		"reveal": "always",
		"panel": "new"
	}
}

The dotnet publish command should be straight forward, it creates a about 100MB of files.

These files should be uploaded, the next task takes care of that.
Code for the upload task via the WinSCPnet.dll is found here. It makes sure that pm2 stops the webpage, uploads all the files and then tells pm2 to start the webpage again.

Configure pm2 to run the aspnet core webpage

In the directory that holds the published files, I created a .sh file, really only containing an execute command

This .sh file can then be used to tell PM2 to use it with ‘pm2 start startTimelapseMP4Webpage.sh’. This new PM2 configuration can be saved with ‘pm2 save’.

Information about the process

Use nginx to act as a reverse proxy

The aspnet core webpage just runs on http://localhost:5020, nothing fancy there. Next we need to use nginx to act as a reverse proxy to make https://vwp.timdows.com/timelapse serving http://localhost:5020.

Running on localhost:5020

As an admin within DirectAdmin we can configure this.

Under Extra Features go to Custom HTTPD Configurations

location /timelapse/ {
    proxy_pass http://localhost:5020/;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_cache_bypass $http_upgrade;
}

Use the above code to make nginx serve the aspnet core webpage.

All done and time for beer ;.)

2 thoughts on “Host a aspnet core webpage on a directadmin environment with pm2

  • Perfect update of captchas solution package “XRumer 16.0 + XEvil 4.0”:
    captchas solution of Google (ReCaptcha-2 and ReCaptcha-3), Facebook, BitFinex, Bing, Hotmail, SolveMedia, Yandex,
    and more than 8400 another subtypes of captcha,
    with highest precision (80..100%) and highest speed (100 img per second).
    You can use XEvil 4.0 with any most popular SEO/SMM programms: iMacros, XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

    Interested? There are a lot of introducing videos about XEvil in YouTube.

    FREE DEMO AVAILABLE!

    Good luck 😉

    http://XEvil.net/

  • Revolutional update of captcha breaking software “XRumer 16.0 + XEvil”:
    captcha solving of Google (ReCaptcha-2 and ReCaptcha-3), Facebook, BitFinex, Bing, Hotmail, SolveMedia, Yandex,
    and more than 8400 another size-types of captchas,
    with highest precision (80..100%) and highest speed (100 img per second).
    You can use XEvil 4.0 with any most popular SEO/SMM programms: iMacros, XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

    Interested? There are a lot of impessive videos about XEvil in YouTube.

    FREE DEMO AVAILABLE!

    See you later 😉

    http://XEvil.net/

Leave a Reply

Your email address will not be published. Required fields are marked *