领导给我一台麒麟V10:你去用 nginx 部署一个前端项目

麒麟 V10 安装 nginx 并部署前端项目

记录纯新手从0开始安装nginx并部署前端项目。

第一步:安装 nginx

1. 确定系统信息

root用户执行nkvers命令查看系统信息:

############## Kylin Linux Version #################
Release:
Kylin Linux Advanced Server release V10 (Sword)

Kernel:
4.19.90-24.4.v2101.ky10.aarch64

Build:
Kylin Linux Advanced Server
release V10 (SP2) /(Sword)-aarch64-Build09/20210524
#################################################

麒麟操作系统:

  • 版本:V10(SP2)
  • 内核:4.19.90-24.4.v2101.ky10.aarch64
  • CPU架构:aarch64

2. 检查是否已安装nginx

切换到root用户,之后的操作都是以root身份进行,然后查看nginx进程:

sudo -i
# [sudo] admin 的密码:
ps -ef | grep nginx
# root       49691   46266  0 14:28 pts/4    00:00:00 grep nginx

如果输出只有一行并且以grep nginx结尾,则说明服务器很干净,你需要先安装nginx服务。

如果输出N多个进程信息,那么恭喜你,可以省去安装步骤:

sudo ps -ef | grep nginx
# root      496080       1  0 6月16 ?       00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
# www-data  497758  496080  0 6月16 ?       00:00:00 nginx: worker process
# www-data  497767  496080  0 6月16 ?       00:00:00 nginx: worker process
# www-data  497768  496080  0 6月16 ?       00:00:00 nginx: worker process
# root      626417  626348  0 14:32 pts/0    00:00:00 grep --color=auto nginx

主进程master process信息中会标识nginx的安装目录,本例为/usr/sbin/nginx

3. 尝试用安装包直接安装

这里非常容易踩坑,极易出现兼容性或者缺少依赖项等问题。我的思路是,先确定系统兼容项,再针对下载特定包。经过网络搜索和AI,大致确定我这个版本的麒麟V10(SP2)CentOS 8更兼容,进一步验证:

检查项目 命令 输出
glibc ldd --version | head -n1 ldd (GNU libc) 2.28
openssl openssl version OpenSSL 1.1.1f 31 Mar 2020
gcc gcc --version | head -n1 gcc (GCC) 7.3.0

确认我的判断。先尝试直接用编译好的安装包安装,如果能成功就省去编译工作:

  • 从 nginx 官网下载CentOS 8兼容的el8版本的安装包nginx-1.30.2-1.el8.ngx.aarch64.rpm
  • 上传到服务器/opt/software/nginx/nginx-1.30.2-1.el8.ngx.aarch64.rpm
  • 执行安装:
cd /opt/software/nginx
rpm -ivh ./nginx-1.30.2-1.el8.ngx.aarch64.rpm

稍微等待片刻便安装成功(忽略其他警告信息):

警告:./nginx-1.30.2-1.el8.ngx.aarch64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID ********: NOKEY
Verifying...                       ################################# [100%]
准备中...                           ################################# [100%]
正在升级/安装...
   1:nginx-1:1.30.2-1.el8.ngx      ################################# [100%]
----------------------------------------------------------------------

Thanks for using nginx!
...
  • 验证安装
nginx -v

nginx version: nginx/1.30.2

which nginx

/usr/sbin/nginx

至此,已经成功在麒麟OS系统安装nginx/1.30.2

4. 启动nginx服务

查看nginx服务状态:

systemctl status nginx

服务状态正常(Active: active (running)):

● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2026-06-18 09:06:16 CST; 6s ago
     Docs: http://nginx.org/en/docs/
  Process: 59666 ExecStart=/usr/sbin/nginx -c ${conffile} (code=exited, status=0/SUCCESS)
 Main PID: 59667 (nginx)
    Tasks: 49
   Memory: 125.4M
   CGroup: /system.slice/nginx.service
           ├─59667 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           ├─59668 nginx: worker process
           ├─59669 nginx: worker process
...

如果nginx服务未能正常启动,则需要排查原因解决问题。

第二步:部署前端应用

假定前端项目是unidmrcore组织的multi-tenant应用:

  • 文件路径是/opt/unidmrcore/multi-tenant/
  • 监听的端口是10115
  • nginx配置文件是/etc/nginx/conf.d/unidmrcore_multi_tenant.conf
  • nginx日志写入:
    • /var/log/nginx/unidmrcore_multi_tenant_access.log
    • /var/log/nginx/unidmrcore_multi_tenant_error.log

1. 准备前端部署文件

  • 上传安装包到/opt/unidmrcore/multi-tenant/dist.zip
  • 解压缩安装包unzip /opt/unidmrcore/multi-tenant/dist.zip -d /opt/unidmrcore/multi-tenant/
  • 确认内容ls /opt/unidmrcore/multi-tenant/dist

2. 配置nginx

  • 创建nginx配置文件:

    tee /etc/nginx/conf.d/unidmrcore_multi_tenant.conf << 'EOF'
    server {
        listen 10115;
        root /opt/unidmrcore/multi-tenant/dist;
        index index.html;
    
        # 字符编码
        charset utf-8;
    
        # 日志配置
        access_log /var/log/nginx/unidmrcore_multi_tenant_access.log;
        error_log /var/log/nginx/unidmrcore_multi_tenant_error.log;
    
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
    EOF
    
  • 验证配置文件并重新加载:

    nginx -t && systemctl reload nginx
    # nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    # nginx: configuration file /etc/nginx/nginx.conf test is successful
    
  • 复核nginx服务状态:

    systemctl status nginx
     # ● nginx.service - nginx - high performance web server
     #    Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
     #    Active: active (running) since Thu 2026-06-18 09:06:16 CST; 34min ago
     #      Docs: http://nginx.org/en/docs/
     #   Process: 59666 ExecStart=/usr/sbin/nginx -c ${conffile} (code=exited, status=0/SUCCESS)
     #   Process: 60358 ExecReload=/bin/sh -c /bin/kill -s HUP $(/bin/cat /run/nginx.pid) (code=exited, status=0/SUCCESS)
     #  Main PID: 59667 (nginx)
     #     Tasks: 49
     #    Memory: 151.3M
     #    CGroup: /system.slice/nginx.service
     #            ├─59667 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
     #            ├─60360 nginx: worker process
     #            ├─60361 nginx: worker process
    

3. 防火墙放行

本机使用的是iptables,放行10115端口,并持久化生效:

iptables -I INPUT -p tcp --dport 10115 -j ACCEPT
service iptables save
# iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]

接下来只需要在本地(能访问通服务器的终端)验证服务器10115端口可以访问即可。

至此,已经完成把nginx安装到麒麟V10并部署前端应用的全部工作。

posted @ 2026-06-18 09:56  Theo·Chan  阅读(24)  评论(0)    收藏  举报