How to setup an asp.net core website

#1
I was trying to setup an asp.net core 5.0 web api service on my Ubuntu 18.04 with openlitespeed but all I found is this old thread

https://forum.openlitespeed.org/threads/asp-net-site.3648/

I'm not trying with mono, is now 2021 where dotnet 5.0 now runs native on linux without problems, all documentation I found is about Apache or nginx, I was trying this tutorial for nginx, but I'm totally lost:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0

I configured an openlitespeed site as other ones that I have running on my ubuntu server, but don't know how to write a similar config on litespeed, like the ngingx suggested in in the above tutorial

This is for ngingx config and must be placed at /etc/nginx/sites-available/default .

server {
listen 80;
server_name example.com *.example.com;
location / {
proxy_pass http://127.0.0.1:5000;
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;
}
}

My question are:

How and where to setup something like the nginx above sample but for OpenLiteSpeed?
There is a Guide to configure an asp.net 5.0 web site that is already running over dotnet 5.0 for OpenLiteSpeed?

Please remember I'm not talking about mono, I'm talking about a native proccess into my linux machine !!!
 
#4
Hi,

After a few modifications on my Ubuntu server I managed to run a ASP.NET razor page website on OpenLiteSpeed with CyberPanel. I am making a manual for others. If interested, I can paste it here.
 
#7
It will take me a week to make it. However, I can tell you the errors I had to face. Make sure your dontnet service file runs on boot automatically. Make sure www-data user has permissions on the dotnet folder and setup virtual host and proxy on openlightspeed. If any error then email me nagpa.ankit@gmail.com
 
#8
I am not an expert in Ubuntu. I am a .NET programmer in WPF, ASP.NET core Razor and Web API projects. My requirement is to run Wordpress (PHP) and ASP.NET website (https://softsolutionslimited.com) on the same domain with at least 2 vCPU and 4 GB RAM, which requires higher hosting plan than a normal shared hosting. So, I had 2 options: to run Wordpress on Windows (IIS) hosting, or run ASP.NET website on PHP web server (OpenLiteSpeed). I also tried Apache and nginx with directadmin panel, but OpenliteSpeed with CyberPanel worked best in combination. I am using Hetzner cloud hosting. When I was not able to run ASP.NET on OpenLiteSpeed, I was using Contabo Windows VPS: https://contabo.com/en/vps/vps-s-ss...ty=1&contract=1&storage-type=vps-s-200-gb-ssd with Plesk panel. The problem was that Windows server licensing is per vCPU of around $5-7 / vCPU, which looks unfair, and there is only one option of hosting panel on Windows: Plesk. On the other hand, there are many options for panels and servers on Linux (Ubuntu), and therefore lots of tutorials on internet for those. So, I am not very comfortable with Windows hosting because of Microsoft licensing and only one panel option, which feels kind-of restricting. It is not about money, but more about freedom in programming. So, I spent 3-4 days to learn Ubuntu and setup both Wordpress and ASP.NET on same server using OpenLiteSpeed and CyberPanel.

I am right now in the middle of setting up the Hetzner cloud, so a little busy for a week. I will be in touch.
 
#10
Steps to run a dotnet project (Website.dll) on CyberPanel and OpenLiteSpeed on a domain: yourdomain.com

Make sure CyberPanel, OpenLiteSpeed and dotnet core 5.0 is installed on the server and SSL is issued for yourdomain.com

--------------------------------------------------------------------

Following should already be added to Website.dll as described in: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0

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

app.UseAuthentication();

--------------------------------------------------------------------

Step 1. Publish the dotnet project in the folder:

/home/yourdomain.com/public_html/

--------------------------------------------------------------------

3. If Website.dll uses database, then make sure you have set the same user and password in your database in CyberPanel:

Change user password in CyberPanel -> Databases -> PhpmyAdmin -> "User Accounts" -> Change Password

--------------------------------------------------------------------

2. Make dotnet Website.dll a service:

Create a service file:

sudo nano /etc/systemd/system/website.service

File contents:

[Unit]
Description=Example .NET Web App running on Ubuntu

[Service]
WorkingDirectory=/home/yourdomain.com/public_html
ExecStart=/usr/bin/dotnet /home/yourdomain.com/public_html/Website.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

--------------------------------------------------------------------

4. Enable the service:

sudo systemctl enable website.service
sudo systemctl daemon-reload
sudo systemctl start website.service

--------------------------------------------------------------------

5. Check if the service is listening to 5000 port using:

sudo systemctl status website.service

--------------------------------------------------------------------

6. Now, the dotnet assembly should be running fine on 5000 port:

localhost:5000

you can check it on Firefox or using curl command

--------------------------------------------------------------------

7. Setup dotnet server in OpenLiteSpeed:

Server Configuration -> External App -> Click "+" button -> Type: Web Server -> Click ">|" button on right side -> Name: dotnet_website -> Address: localhost:5000 -> Max Connections: 1900 -> Initial Request Timeout (secs): 5 -> Retry Timeout (secs) -> 5

8. Perform graceful restart of OpenLiteSpeed at top-right Reset button.

9. "Virtual Hosts" -> yourdomain.com -> Context -> Click "+" button -> Type: Proxy -> Click ">|" button on right side -> Enter URI as a slash (root): / -> Click save button on right side

10. Perform graceful restart of OpenLiteSpeed at top-right Reset button.
 
#12
Steps to run a dotnet project (Website.dll) on CyberPanel and OpenLiteSpeed on a domain: yourdomain.com

Make sure CyberPanel, OpenLiteSpeed and dotnet core 5.0 is installed on the server and SSL is issued for yourdomain.com

--------------------------------------------------------------------

Following should already be added to Website.dll as described in: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-5.0

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
......
thank you very much. worked perfectly.
 
#14
@ankit_nagpal , Couldn't you also do the following:

cat > /etc/systemd/system/website.service << EOF
[Unit]
Description=Example .NET Web App running on Ubuntu

[Service]
WorkingDirectory=/home/yourdomain.com/public_html
ExecStart=/usr/bin/dotnet /home/yourdomain.com/public_html/Website.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target
EOF
 
#20
@Cold-Egg I did the following steps for my Blazor application. The page loads fine, however, it cannot establish a websocket connection to my server. I tried adding ports 80, 5000, and 5001 for "/" in my WebSocket configuration in OpenLiteSpeed, but that does not fix the issue of the web socket.

The rest of the app loads fine though, it just cannot establish a WebSocket connection. How do I fix this?
 
Top