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!
分類: Linux
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無法更新套件
上傳圖片的時候遇到這個錯誤
在 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
Centos 7 SAMBA 安裝
CentOS7 的那些事
永久關閉 port 10000
# sudo firewall-cmd --add-port=10000/tcp --permanent
# sudo firewall-cmd --reload
如果想像以前一樣, 可以手動修改 /etc/resolv.conf 檔案, 先開啟檔案
# vim /etc/NetworkManager/NetworkManager.conf
在 “main” 的段落加入:
dns=none
儲存檔案後, 重新啟動 NetworkManager:
# systemctl restart NetworkManager.service
之後就可以手動修改 /etc/resolv.conf 設定 DNS 伺服器。
centos 7 安裝 guacamole 0.9.13
Linux 安裝 clamav
1.安裝ClamAV防毒程式,此功能只提供命令列控制
sudo apt-get install clamav
2.更新病毒碼
sudo freshclam
3.執行掃毒
例如掃描/home下面所有目錄與檔案
clamscan -i -r /home
-r :遞迴掃描,包含底下所有子目錄
-i :只顯示受感染的檔案
若想要移除受感染的檔案須使用 --remove
例如掃描/home下的所有目錄與檔案,顯示出受感染的檔案並刪除
clamscan -r --remove /home
4.安裝ClamAV-daemon使其常駐執行
sudo apt-get install clamav-daemon
5.檢查ClamAV-daemon是否已啟用
ps aux|grep [c]lamd
若是執行成功會出現類似下列訊息
clam av 15452 0.0 5.7 146576119484 ? Ssl 16:46 0:00 /usr/sbin/clamd
6.檢查目前使用ClamAV版本
clamscan - V
會出現類似下列訊息
ClamAV 0.97.6/16105/Wed Dec 26 13:38:08 2012
7.設定掃毒排程
sudo gedit /etc/crontab
在檔案最下方加上下列資料
#每六小時更新病毒碼
*/3600 * * * * root /usr/bin/freshclam --quiet -l /var/log/clamav/freshclam.log
或是每天03:00更新病毒碼
0 3 * * * root /usr/bin/freshclam --quiet -l /var/log/clamav/freshclam.log
每天子夜掃描所有目錄檔案
00 00 * * * root clamscan -r /
如果要移除ClamAV,請執行下列語法
sudo apt-get --purge remove clamav clamav-base clamav-daemin clamav-freshclam livclamav2
如果需要使用圖形化界面的ClamAV,可以安裝ClamTK
安裝完須設定偏好設定,設定合適的掃描偏好設定
安裝clamTK sudo apt-get install clamtk
使用apt-get安裝的ClamTK常常不是最新的,可以透過ClamTK官網下載新版安裝升級
下載完成Ubuntu軟體中心會偵測到有升級程式,會詢問要不要升級,若沒詢問是否自動升級請執行下列步驟
假設下載最新檔案是clamtk_4.44-1_all.deb
執行
1.sudo dpkg -i clamtk_4.44-1_all.deb
2.sudo apt-get install -f
8.設定postfix整合clamav
編輯 /etc/postfix/master.cf ,加入以下設定
#for amavisd-new
smtp-amavis unix - - n - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks,no_milters
-o smtpd_helo_restrictions=
-o smtpd_client_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o smtpd_authorized_xforward_hosts=127.0.0.0/8
編輯main.cf,加入以下設定
content_filter = smtp-amavis:[127.0.0.1]:10024
#最後在webmin 模組安裝管理介面
Debian 安裝 rsync Server
# apt install rsync
# nano /etc/rsyncd.conf
------------------------------------------------------------------------------------# sample rsyncd.conf configuration file
# GLOBAL OPTIONS
#motd file=/etc/motd
log file=/var/log/rsyncd.log
# for pid file, do not use /var/run/rsync.pid if
# you are going to run rsync out of the init.d script.
# The init.d script does its own pid file handling,
# so omit the "pid file" line completely in that case.
pid file=/var/run/rsyncd.pid
#syslog facility=daemon
#socket options=
# MODULE OPTIONS
[myrsync]
comment = public archive
path = /myrsync
use chroot = yes
# max connections=10
lock file = /var/lock/rsyncd
# the default for read only is yes...
read only = no
list = yes
uid = nobody
gid = nogroup
# exclude =
# exclude from =
# include =
# include from =
auth users =admin
secrets file = /etc/rsyncd.secrets
strict modes = yes
# hosts allow =
# hosts deny =
ignore errors = yes
ignore nonreadable = yes
transfer logging = yes
# log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
timeout = 600
refuse options = checksum dry-run
dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
--------------------------------------------------------------
# nano /etc/rsyncd.secrets
# nano /etc/default/rsync
#chown root:root /etc/rsyncd.secrets
#chmod 600 /etc/rsyncd.secrets
#/etc/init.d/rsync start
在Linux client 到 Rsync Server:
rsync -avzrHS --delete /sftpserver/uploadrsync/ hotai@s2.ice.com.tw::uploadrsync
Ubuntu 的那些事
中文化
先安裝相關組件:
#sudo apt install -y language-pack-zh-hant
修改為以下內容
#sudo nano /etc/default/locale
LANG="zh_TW.UTF-8"
LANGUAGE="zh_TW:zh"