This server should be powered by ASP.NET Core Runtime 3.1.0 / 5.0 / 6.0, systemd and nginx.
- Build this project to get the binary output. Or, get the built version directly.
- Create a folder for this service on server. The path of this folder should override
<path/to/the/folder>
in the code below and the configuration files related. - Copy binary files to this folder.
- Change permission by these commands:
sudo chown -R www-data:www-data <path/to/the/folder>
sudo chmod -R 755 <path/to/the/folder>
- Create a service file in /etc/systemd/system, named as
shorturl.service
. - Place the text from the example to this service file, replacing
<port>
to the number of a chosen free tcp port, and the<path/to/the/folder>
as well. - Reload systemd by
systemctl daemon-reload
. - Start this service by
systemctl start shorturl.service
. - If everything goes will, you can see the port is listed in
lsof -i -P -n | grep LISTEN
. At last, set this service to start with system bysystemctl enable shorturl.service
.
All settings of ShortUrl is saved in file SecretNest.ShortUrl.Setting.json
placed in the folder of this service. If the service is started without the file, the file will be created with default values. Before changing the file, the service should be stopped at first.
To change some core setting, which cannot be changed by management page, follow these steps:
- Stop the service by
systemctl stop shorturl.service
. - Edit the file
SecretNest.ShortUrl.Setting.json
. enableStaticFiles
could be set totrue
orfalse
. When enabled, all requests matched with path of a static file located in the folder specified will be served with the file data directly.userSpecifiedStaticFileFolder
could be set to a path of a folder, which is used to place all static files. This value is read only whenenableStaticFiles
is set totrue
. If this is set tonull
or empty string, the default value (wwwroot
folder under the service folder) will be used.preferXForwardedHost
could be set totrue
orfalse
. When enabled, host name is read first from theX-Forwarded-Host
of the header. When using ShortUrl after a proxy, this value should be set totrue
. Otherwise, set this value tofalse
for security purposes. For being accessed through Nginx reverse proxy, this value should be set totrue
.- All other settings can be changed by management page. Changing value in file is NOT recommended unless you cannot use HTTPS protocol for managing.
- You should note the value of
globalManagementKey
for entering the management page.
- Create a site file in
/etc/nginx/sites-available
named as you wish, likeexample.com
for example. - Choose from one.
- If you want to use CertBot from Let's Encrypt later, place the text from the example to this site file, replacing to the number of the chosen tcp port for service, and the <SERVER_DOMAIN> to the domain name or names. Using HTTP only for servicing is acceptable. But using HTTP for management pages is highly NOT recommended.
- If you want to use your own HTTPS certificate, place the text from the example to this site file, replacing to the number of the chosen tcp port for service, the <SERVER_DOMAIN> to the domain name or names, and the paths of the certificate files.
- Enable this site by
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled
. - Test configuration by
nginx -t
. - Reload nginx by
systemctl reload nginx
. - (Optional) Use CertBot to enable the HTTPS for this site. HTTP redirection is not required.
By navigating to the server domain, you should be redirect to the default page (google.com in default config).
- Enter the Global Management page by navigating to
https://yourdomain/<globalManagementKey>
.- This domain should be listed as global management enabled hosts. All domains are enabled if this list is empty.
<globalManagementKey>
can be obtained from the configuration file by the step 7 of Main configuration stage.<globalManagementKey>
is displayed and can be changed in Global Management page.
- Enter Domain Management page by navigating to
https://yourdomain/<domainManagementKey>
.- By pressing the Manage button after the domain listed in Global Management page, browser will open this page as well.
<domainManagementKey>
can be obtained from the configuration file.<globalManagementKey>
is displaned and can be changed in Domain Management page.
See this document for details.