preface
Recently, the company needs development projects that can run on Linux systems. The example development projects are developed using. NET Core + Angular; in theory, cross-platform is fully supported.
But practice is the only criterion for testing truth; then it is better to verify and implement it with hands; if any problems occur during the process, it can be regarded as accumulating experience.
1. Environmental preparation
由于本次主要验证项目部署 Linux 环境,也不想去重新搭建一个虚拟机环境;就使用 Win10 中 Linux 子系统(WSL 什么?)
- Steps to enable WSL:
- Go to [Enable or Disable Windows Functions] to enable WSL, as shown below

- Go to the Microsoft store and select the corresponding version. CentOS is installed on this machine

- When booting after installation is complete (problems occur)

最终确定问题原因:需要更新 Linux 内核包(更新包下载地址:https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi)
After downloading and installing, the CentOS system environment is ready.
- NET Core environment installation:
- Update the basic software version of the system (may not be implemented)
sudo yum update
- Register Microsoft signature key:
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
- 安装.NET Core SDK,示例程序采用 3.1 版本开发(站长注:现在 2022 年 5 月 11 日,.NET 7 Preview 4已经发布)
sudo yum install dotnet-sdk-3.1
- Check that the installation was successful. The picture shows that the installation has been successful.

- Nginx environment installation: (deploy web projects)
- Environment-dependent installation
yum install gcc-c++
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl--devel
- Add Nginx's yum library
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- install Nginx
sudo yum install nginx
- Basic information about Nginx
Directory structure:
| Nginx Directory | |
|---|---|
| configuration path | /etc/nginx/ |
| error log | /var/log/nginx/error.log |
| access log | /var/log/nginx/access.log |
| Default site directory/usr/share/nginx/html |
Basic command:
- nginx //Start nginx
- nginx -s quit //Stop nginx
- nginx -s reload //Reload configuration file
2. Project deployment
There are many ways to deploy projects to CentOS: direct run and Docker deployment (used many times in the previous study article). This time, we will use direct run to deploy applications. Since the project uses separation of front and back ends, it needs to be deployed separately
- Server deployment
- Copy the server project files to the CentOS directory: The deployment path for this time is: /home/www/publish

- Modify the configuration file: you need to use the vim command (you need to install it separately)
Enter the configuration file editing via the command:
vim appsettings.json
Exit with the following command after editing is completed
vim命令
:w 保存但不退出
:wq 保存并退出
:q 退出
:q! 强制退出,不保存
:e! 放弃所有修改,从上次保存文件开始再编辑命令历史

- Start the service
Enter the project directory and execute the command:
[root@Coder supervisor]# cd /home/www/publish
[root@Coder publish]# dotnet ZLSoft.UnifiedDS.Web.Host.dll --urls http://*:8220

- Front-end project deployment
1、将 web 项目拷贝到:/home/www/web
- Add the configuration file web.conf to the Nginx configuration file directory
server {
listen 8221;
server_name 192.168.243.86:8220;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /home/www/web;
index index.html index.htm;
try_files $uri $uri/ /index.html?$query_string;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
** Note: Since route redirection is used in Angular projects, markup content is required **
- Update Nginx configuration file:
/usr/sbin/nginx -s reload
3. Operation examples
Server operation:

Web project operation effect:

This project has run successfully, but when I finish running the CentOS command, the web server stops running, so I need to implement the creation service as a daemon process.
4. Daemon creation-supervisor
- Install the supervisor
#安装python的扩展
yum install python-setuptools
#通过python的扩展安装supervisor
easy_install supervisor
#建立设置文件夹
mkdir /etc/supervisor
mkdir /etc/supervisor/conf.d
#设置文件
echo_supervisord_conf > /etc/supervisor/supervisord.conf
#修改设置文件(supervisord.d 文件夹下的所有 ini 类型的文件都是配置文件)
#在文件/etc/supervisor/supervisord.conf末端
;files = relative/directory/*.ini 改为 files = conf.d/*.ini
2、创建配置文件:在/etc/supervisor/conf.d目录下创建publish.conf
[program:publish]
command=dotnet ZLSoft.UnifiedDS.Web.Host.dll --urls http://192.168.243.86:8220 #运行命令
directory=/home/www/publish #程序路径
environment=ASPNETCORE__ENVIRONMENT=Production
user=root
stopsignal=INT
autostart=true #自动启动
autorestart=true #3秒自动重启
startsecs=3
stderr_logfile=/var/log/ossoffical.err.log
stdout_logfile=/var/log/ossoffical.out.log
- Start the service
#进入supervisor目录
cd /etc/supervisor
#启动supervisord 服务
supervisord -c supervisord.conf
- Enable the interface management function of the daemon process
#修改配置文件:
vim /etc/supervisord.conf
#取消注释内容
[inet_http_server] ; inet (TCP) server disabled by default
port=*:9001 ; ip_address:port specifier, *:port for all iface
username=user ; default is no username (open server)
password=123 ; default is no password (open server)
#重新加载配置文件
supervisorctl reload
- Supervisorctl common commands
$ sudo service supervisor stop 停止supervisor服务
$ sudo service supervisor start 启动supervisor服务
$ supervisorctl shutdown #关闭所有任务
$ supervisorctl stop|start program_name #启动或停止服务
$ supervisorctl status #查看所有任务状态
V. Summary
Running deployment and operation projects in the CentOS system mainly depends on whether you are proficient in Linux-related content: such as commands, permissions, software and other related content. No matter what you need, you can still make skills. Practice more.
In addition, the Linux system in WSL is still not comprehensive enough, and there are no ** services and firewall ** related functions for the time being. Therefore, if you are in a real environment, you can set up service booting and firewall related processing.
So you still need to find a complete environment to study and practice.