Deploying an ASP.NET Core 7 App on CentOS 7.9 with aaPanel
Switch to the root account before anything else:
sudo -i
- Install aaPanel 8.x
# CentOS 7/8
yum install -y wget \
&& wget -O install.sh http://download.bt.cn/install/install_6.0.sh \
&& bash install.sh
# Ubuntu / Deepin
wget -O install.sh https://download.bt.cn/install/install-ubuntu_6.0.sh \
&& sudo bash install.sh
After the script finishes, note the login URL, username and password.
- Add Microsoft package feed
# CentOS 7
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
# CentOS 8
sudo rpm -Uvh https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm
If you see a conflict error, force the install:
sudo rpm -Uvh --nodeps --force packages-microsoft-prod.rpm
- Install .NET 7 runtime (optional)
# CentOS
sudo yum -y install aspnetcore-runtime-7.0
# Ubuntu / Deepin
sudo apt-get update \
&& sudo apt-get install -y aspnetcore-runtime-7.0
Verify:
dotnet --info
- Publish the applicaiton
- Self-contained: no runtime needed on the server, larger package.
- Framework-dependent: smaller package, runtime must be installed (step 3).
- Upload & test locally
# 1. Upload publish folder to /www/wwwroot/myApp
cd /www/wwwroot/myApp
# 2a. Framework-dependent
dotnet MyApp.dll
# 2b. Self-contained single-file
yum install -y icu
chmod +x ./MyApp
./MyApp
You should see Now listening on: http://localhost:5000.
- Configure Nginx reverse proxy
- Open aaPanel → Websites → your site → Reverse proxy.
- Add a proxy rule: ```
Name: dotnet_backend
Target URL: http://localhost:5000
Send domain: $host
- Keep the app alive with Supervisor
# Install
yum install -y supervisor
systemctl enable supervisord --now
Create /etc/supervisord.d/myApp.ini:
[program:myApp]
command=/usr/bin/dotnet /www/wwwroot/myApp/MyApp.dll # or ./MyApp for self-contained
directory=/www/wwwroot/myApp
user=root
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/myApp.log
stderr_logfile=/var/log/supervisor/myApp_error.log
supervisorctl reread
supervisorctl update
supervisorctl start myApp
- SPA static-file issues
If you see:
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html'
Upload the built front-end to ClientApp/dist and adjust Startup.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseStaticFiles();
var spaDist = new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath, "ClientApp/dist"))
};
app.UseSpaStaticFiles(spaDist);
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSpa(spa =>
{
spa.Options.DefaultPageStaticFileOptions = spaDist;
});
}