ASP.Net Core on Linux
Todays Achievements:
- Ran ASP.Net Core on Ubuntu Linux, with Identity Support
Why:
- Potential for cost savings using Linux VM's over Windows VM's
- Also allows for splitting the hosting, ie: SQL Server on one machine and ASP.Net on another, I can get 2 x Linux machine with same spec as a single Windows VM on AWS Lightsail
- 2 CPU's
- 4GB RAM
- 80 GB SSD
- US$20 per month - Windows is $40 per month
Gotcha's
- Needs apache to proxy the request to Kestrel
- Not sure about the proxy to https://localhost:5001
- Not sure about the processor overhead of the proxy work.
Questions
- Runtime Compilation - Does it slow the app down in production ?
- Does Reverse Proxy well deployed on Linux need https ?
- Answer: No, see Enforce HTTPS in ASP.NET Core | Microsoft Docs
- In some backend service scenarios where connection security is handled at the public-facing edge of the network, configuring connection security at each node isn't required. Web apps that are generated from the templates in Visual Studio or from the dotnet new command enable HTTPS redirection and HSTS. For deployments that don't require these scenarios, you can opt-out of HTTPS/HSTS when the app is created from the template.
Key Steps
- From Microsoft doco, Host ASP.NET Core on Linux with Apache | Microsoft Docs
- Also another guide at Syncfusion Hosting Multiple ASP.NET Core Apps in Ubuntu Linux Server Using Apache (syncfusion.com)
- In Startup.Configure (localhost is trusted by default, for other machines, add options.KnownProxies.Add( Uri ))
app.UseForwardedHeaders(new
// Place as one of the first entries, perhaps after any IsDevelopment code
ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
- In appache conf
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName www.example.com
ServerAlias *.example.com
ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
</VirtualHost>
- Create a service
[Unit] Description=Example .NET Web API App running on CentOS 7 [Service] WorkingDirectory=/var/www/helloapp ExecStart=/usr/local/bin/dotnet /var/www/helloapp/helloapp.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dotnet-example User=apache Environment=ASPNETCORE_ENVIRONMENT=Production [Install] WantedBy=multi-user.target
|
|
|
Comments
Post a Comment