Installing DBGate
DBGate is an ASP.NET Core application built on the cross-platform Kestrel web server for ASP.NET Core.
Kestrel can be used by itself or with a reverse proxy server, such as Internet Information Services (IIS), Nginx, or Apache.
Below are useful links to learn about installing and tuning ASP.NET Core applications in different scenarios:
- Host ASP.NET Core on Windows with IIS
- Host ASP.NET Core on Linux with Nginx
- Host ASP.NET Core on Linux with Apache
- Kestrel web server implementation in ASP.NET Core
Below are the short step-by-step guides that help to deploy DBGate for the first time.
Installing DBGate on Windows
- Enable IIS on your machine.
- Install the .NET Core Hosting Bundle
- Restart IIS.
- Copy the dbgate subfolder from the DBGate download package to your local drive. For example, copy it to the C:\inetpub folder.
- Add connection strings for your databases to the appsettings.Production.json file.
- Create a DBGate application pool.
- Create a DBGate website or application.
Creating DBGate Application Pool
Open the IIS Manager, select Application Pools, and click the Add Application Pool... action to create an application pool.
Use the following values:
- Name: dbgate
- .NET CLR version: No Managed Code
- Managed pipeline code: Integrated
Creating DBGate Website
Use this scenario to create a subdomain like dbgate.contoso.com.
Also, use it to create a local website accessible through a URL like http://dbgate.
In the last case, also add the following line to the c:\windows\system32\drivers\etc\hosts file:
127.0.0.1 dbgate
To create a website, select the Sites node and click the Add Website... action.
Then use the following values:
Note that it is important to choose the dbgate application pool created in the previous step.
To test the local website installation, open the URL:
http://dbgate
You have to see the index page. Play with samples. DBGate loads data from an online SQL Server database.
For example, try the s02/cashbook table:
Configuring HTTPS Certificate on Windows
Do not use DBGate over HTTP as it uses the basic authentication and sends logins and passwords as plain text.
Always turn on HTTPS and redirect HTTP to HTTPS.
Below are the steps to create a self-signed certificate.
- Open Windows PowerShell (Admin) and execute the command:
New-SelfSignedCertificate -NotBefore (Get-Date) -NotAfter (Get-Date).AddYears(5) -DnsName "localhost", "dbgate" -KeyAlgorithm "RSA" -KeyLength 2048 -HashAlgorithm "SHA256" -CertStoreLocation "Cert:\LocalMachine\My" -KeyUsage KeyEncipherment -FriendlyName "DBGate Certificate" -TextExtension @("2.5.29.19={critical}{text}","2.5.29.37={critical}{text}1.3.6.1.5.5.7.3.1")
It creates a self-signed certificate for localhost and dbgate hosts.
See more details here: New-SelfSignedCertificate
Open
certlm.msc
and copy the DBGate Certificate from the Personal Certificates store to Trusted Root Certification Authorities.Open
IIS Manager
, select Default Web Site and its bindings.
Select HTTPS, click Edit..., and select DBGate Certificate in the SSL Certificate list. Click OK.
To roll back the changes, restore the initial SSL certificate first and delete the DBGate Certificate using the certlm.msc.
Creating DBGate Application
Use this scenario to create an application like www.contoso.com/dbgate or localhost/dbgate.
To create an application, select the desired website node, right-click on it, and click the Add Application... action.
Then use the following values:
Note that it is important to choose the dbgate application pool created in the previous step.
If you use DBGate as an IIS application, replace the <base href="/"> line to <base href="/dbgate/"> in the following files:
- C:\inetpub\dbgate\wwwroot\edit.htm
- C:\inetpub\dbgate\wwwroot\index.htm
To test the localhost application, open the URL:
http://localhost/dbgate
You have to see the index page. Play with samples. DBGate loads data from an online SQL Server database.
For example, try the s02/cashbook table:
Installing DBGate on Linux
Here are the complete guides:
In short, make the following steps:
- Install ASP.NET Core Runtime 3.1 for DBGate 1.x and ASP.NET Core Runtime 6.0 for DBGate 2.x.
- Copy the dbgate subfolder from the DBGate download package to the /var/www folder.
- Add connection strings for your databases to the appsettings.Production.json file.
- Check or change the default Kestrel DBGate port 5003 in the appsettings.Production.json file.
- Create a service file to manage the Kestrel process and enable the service.
- Create a DBGate subdomain.
- Configure an HTTPS certificate.
Creating a service file to manage the Kestrel process and enabling the service
Here is a complete guide: Create the service file
We recommend creating the /etc/systemd/system/kestrel-dbgate.service file with the following content:
[Unit] Description=dbgate [Service] WorkingDirectory=/var/www/dbgate ExecStart=/usr/bin/dotnet /var/www/dbgate/dbgate.dll Restart=on-failure Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 KillSignal=SIGINT SyslogIdentifier=dotnet-dbgate User=www-data Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.target
After creating the file, enable and start the service:
sudo systemctl enable kestrel-dbgate.service sudo systemctl start kestrel-dbgate.service sudo systemctl status kestrel-dbgate.service
To test the service, try to get data using a command like this:
curl http://localhost:5003/api/mssql-023/s02/cashbook
Creating a DBGate subdomain
To create a subdomain, make the following steps:
- Create the DNS A record for your domain.
- Add a subdomain section to your domain configuration file.
Here is an Nginx configuration of the dbgate.savetodb.com subdomain:
server { server_name dbgate.savetodb.com; location / { proxy_pass http://localhost:5003; 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; } }
Configuring an HTTPS certificate on Linux
We recommend reading this resource: Secure HTTP Traffic with Certbot