1.安裝 NET 7 Runtime
查看已安裝的版本dotnet --list-runtimes
2.安裝 Apache server
Apache server will act as a reverse proxy and pass the request to the Kestrel Server from the internet.
2_1. Let’s install the Apache server in the Linux machine using the following command:
sudo apt install apache2
2_2.After installing the Apache Server, install the following required modules:
sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod ssl2_3.Now, restart the Apache server using the following command:
sudo systemctl restart
apache2
3.上傳網站內容到服務器.
4. 為網站建立一個服務檔案
#sudo nano /etc/systemd/system/xxx.ice.com.tw.service
[Unit]
/xxx.
Description=Running ASP.NET Core on debian 11 Webserver APACHE
[Service]
WorkingDirectory=/sftserver/web/xxx.ice.com.tw/
ExecStart=/usr/bin/dotnet /sftpserver/web/xxx.ice.com.twdll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
In the above configuration,
WorkingDirectory defines the folder from which the service will run.
ExecStart defines the application to be started in this service.
Then, move the newly created file to the Linux server in the location etc/systemd/system/ using FileZilla. Enable and start the service using the following command in PuTTY:sudo systemctl enable
xxx.ice.com.tw
.service
sudo systemctl startxxx.ice.com.tw
.service
5. 建立Apach組態檔案
#sudo nano /etc/apache2/sites-available/.conf
xxx.ice.com.tw
figuration file
Create a new host configuration file named sample.conf and add the following configuration to it:<VirtualHost *:80>
ServerName
xxx.ice.com.tw
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ErrorLog ${APACHE_LOG_DIR}/.-error.log
xxx.ice.com.tw
</VirtualHost>
In the above configuration:
VirtualHost *:80 means that the site is hosted under port 80.
Domain URL is given in the ServerName.
For proxypass and proxypassreverse, we have provided the Kestrel server that is running locally and its default port is 5000.
All the application’s config files are located in the file path etc/apache2/sites-available in the Linux server. So, move the created config file to the Linux server under this folder.
Now, enable the new site configuration using the following command:
#sudo a2ensite xxx.ice.com.tw.conf
Check the syntax of the configuration using the following command:sudo apachectl configtest
If there is no error, then your site is ready to go!
5. 建立第2個以後ASP.NET Core 網站
We have seen how to create a service and config file to host an ASP.NET Core application in a Linux server. Now, let’s see how you can host another application on the same Linux server. To do so, follow these steps:
Move the new application sample to the Linux server under the file path /var/www/sample1.
Then, create a new service file named sample1.service and add the following configuration to it. Here, we will add the port from which the new sample application will be hosted.[Unit]
Description=Running ASP.NET Core on Ubuntu 18.04 Webserver APACHE
[Service]
WorkingDirectory=/var/www/sample/
ExecStart=/usr/bin/dotnet /var/www/sample/sample.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=http://127.0.0.1:5001
[Install]
WantedBy=multi-user.target
Move the service and enable it by following the steps given in the Create a service to Run the application section.
Now, create a new host configuration file named sample1.conf and add the following command to it. Here, for proxy, use the new port 5001.<ltVirtualHost *:80>
ServerName www.sample1.com
ProxyPreserveHost On
ProxyPass / http:// 127.0.0.1:5001/
ProxyPassReverse / http:// 127.0.0.1:5001/
ErrorLog ${APACHE_LOG_DIR}/sample-error.log
</VirtualHost>
Finally, move the .conf file to the Linux server and then enable the site. Now, you can access the new hosted application.
Note: Similarly, you can host any number of applications using the app’s port in the Linux server.
Conclusion
Thanks for reading! In this blog post, we have seen how to host multiple ASP.NET Core applications in a Linux Ubuntu server using Apache as a reverse proxy. With this approach, hosting an ASP.NET Core app in Linux isn’t complicated. So, try out the steps provided in this blog post and leave your feedback in the comments section.
The Syncfusion ASP.NET Core UI controls library powered by Essential JS 2 is the only suite that you will ever need to build an application since it contains over 70 high-performance, lightweight, modular, and responsive UI controls in a single package. Use them to increase your productivity in app development!
If you’re already a Syncfusion user, you can download the product setup, or, you can download a free 30-day trial to evaluate our products.
You can also contact us through our support forum, Direct-Trac, or feedback portal. As always, we are happy to assist you!
作者: simon
rocky linux 安裝後的那些事
#中文化
dnf -y install langpacks-zh_TW
localectl set-locale LANG=zh_TW.utf8
reboot
#更改台灣時區
timedatectl set-timezone Asia/Taipei
讓其他使用者可以執行 sudo
chmod u+w /etc/sudoers
nano /etc/sudoers
將 simon ALL=(ALL) ALL 加到底下
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
★★ 永久性的關掉 selinux ★★
$ sudo nano /etc/sysconfig/selinux
找到
SELINUX=enforcing
然後修改為
SELINUX=disabled
要重新開機 reboot / restart 後才會套用
參考資料
新增硬碟-LVM
Rocky Linux 8 安裝及設定Nginx多網域
Install WordPress with Nginx on Rocky
解決Nginx無法更新套件
上傳圖片的時候遇到這個錯誤
Proxmox 升級重啟後某個lvm硬碟無法掛載
TASK ERROR: activating LV 'local-4tb/local-4tb' failed:
Activation of logical volume local-4tb/local-4tb is prohibited while logical volume local-4tb/local-4tb_tmeta is active
1.先備份
cp /etc/lvm/lvm.conf /etc/lvm/lvm.backup
2.編輯 nano /etc/lvm/lvm.conf
加以下列
thin_check_options = [ "-q", "--skip-mappings" ]
存檔後執行 update-initramfs -u
重新開機
3.lvchange -a n lvm/lvm_tmeta
lvchange -a n lvm/lvm_tdata
lvchange -ay
例如
lvchange -a n local-4tb/local-4tb_tmeta
lvchange -a n local-4tb/local-4tb_tdata
在 Webmin 安裝 SSL 證書
almalinux 8.6安裝、設定及升級Gitea
安裝
To upgrade to the latest Gitea version, simply download and replace the binary.
- Stop the Gitea service:
sudo systemctl stop gitea
Download the latest Gitea version and move it to the /usr/local/bin
directory:
VERSION=<THE_LATEST_GITEA_VERSION>
wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64
sudo mv /tmp/gitea /usr/local/bin
Make the binary executable:
sudo chmod +x /usr/local/bin/gitea
Restart the Gitea service:
sudo systemctl restart gitea
將 sql server 備份到網路磁碟機
1.打開XP_CMDSHELL指令
EXEC master.dbo.sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC master.dbo.sp_configure 'xp_cmdshell', 1;
RECONFIGURE WITH OVERRIDE;
2.設定網路磁碟機
exec xp_cmdshell 'net use T: \\192.168.1.94\backup "password" /user:simon /y'
3.加入sql server 排程
server core 防火牆管理
netsh advfirewall firewall set rule group = "檔案及印表機共用" new enable=yes
Hyper-V @%systemroot%system32vmms.exe,-210 Hyper-V 管理用戶端 @%ProgramFiles%Hyper-VSnapInAbout.... Hyper-V 複本 HTTP @%systemroot%system32vmms.exe,-251 Hyper-V 複本 HTTPS @%systemroot%system32vmms.exe,-253 iSCSI 服務 @FirewallAPI.dll,-29002 Netlogon 服務 @netlogon.dll,-1010 SMB Witness @witness.dll,-9001 SMBDirect 上的檔案及印表機共用 @FirewallAPI.dll,-28602 SNMP Trap @snmptrap.exe,-3 TPM 虛擬智慧卡管理 @FirewallAPI.dll,-36501 Windows Management Instrumentation (... @FirewallAPI.dll,-34251 Windows 防火牆遠端管理 @FirewallAPI.dll,-30002 Windows 遠端管理 @FirewallAPI.dll,-30267 Windows 遠端管理 (相容性) @FirewallAPI.dll,-30252 分散式交易協調器 @FirewallAPI.dll,-33502 金鑰管理服務 @FirewallAPI.dll,-28002 容錯移轉叢集 @cprepsrv.dll,-1000 效能記錄及警示 @FirewallAPI.dll,-34752 核心網路功能 @FirewallAPI.dll,-25000 虛擬機器監視 @vmicres.dll,-700 路由及遠端存取 @FirewallAPI.dll,-33752 網路探索 @FirewallAPI.dll,-32752 遠端事件記錄檔管理 @FirewallAPI.dll,-29252 遠端服務管理 @FirewallAPI.dll,-29502 遠端桌面 @FirewallAPI.dll,-28752 遠端排程工作管理 @FirewallAPI.dll,-33252 遠端磁碟區管理 @FirewallAPI.dll,-34501 遠端關機 @firewallapi.dll,-36751 檔案及印表機共用 @FirewallAPI.dll,-28502 檔案伺服器遠端管理 @fssmres.dll,-100
MariaDB 的那些事
Server core 安裝及更新 sql 2019
安裝:
Setup.exe /QS /ACTION=Install /FEATURES=SQLEngine /INSTANCENAME=MSSQLSERVER /IACCEPTSQLSERVERLICENSETERMS=1 /UPDATEENABLED=False /SAPWD=P@ssw0rd /SECURITYMODE=SQL /TCPENABLED=1 /SQLSYSADMINACCOUNTS=BUILTIN\Administrators /AGTSVCACCOUNT="NT AUTHORITY\Network Service"
防火牆:
netsh advfirewall firewall add rule name = SQLPort dir = in protocol = tcp action = allow localport = 1433 remoteip = any profile = DOMAIN
netsh advfirewall firewall add rule name = SQLPort dir = in protocol = tcp action = allow localport = 1433 remoteip = localsubnet profile = DOMAIN
Enable-NetFirewallRule -DisplayGroup "遠端服務管理"
更新: SQLServer2017-KB4466404-x64.exe /qs /IAcceptSQLServerLicenseTerms /Action=Patch /AllInstances