it编程 > 数据库 > Redis

银河麒麟(Kylin)离线安装Nginx并部署多服务完整步骤

55人参与 2026-02-07 Redis

本文介绍如何在 银河麒麟操作系统(kylin v10)上进行 nginx 的离线安装与配置,包括依赖包下载、https 配置、多端口站点部署等完整步骤。

1. 准备环境

由于是离线安装,需要提前下载 nginx 及其依赖的 rpm 包。

银河麒麟官方镜像地址示例:https://update.cs2c.com.cn/ns/v10/v10sp3/os/adv/lic/updates/x86_64/packages/

其中 v10v10sp3x86_64 根据你的系统版本和 cpu 架构调整。

需要下载以下 rpm 包(注意版本匹配):

2. 安装 nginx 及依赖

将下载好的 rpm 包放到 /tmp/nginx_rpm/ 目录:

cd /tmp/nginx_rpm/
rpm -ivh *.rpm --force --nodeps

3. 生成 ssl 证书

创建证书目录:

mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl

生成自签名证书(有效期 365 天):

openssl req -newkey rsa:2048 -nodes -keyout test.key \
    -x509 -days 365 -out test.crt \
    -subj "/c=cn/st=beijing/l=beijing/o=test/ou=it/cn=localhost"

4. 创建测试站点目录

mkdir -p /var/www/test-web
mkdir -p /var/www/test-app
echo "web index" > /var/www/test-web/index.html
echo "app index" > /var/www/test-app/index.html

5. 配置 nginx

编辑 /etc/nginx/nginx.conf(替换原内容):

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    # gzip 压缩
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/json application/javascript application/xml;
    gzip_vary on;

    sendfile        on;
    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;
}

6. 新建多站点配置文件

新建 /etc/nginx/conf.d/project.conf

# web http → https
server {
    listen 80;
    server_name localhost;
    return 301 https://$server_name$request_uri;
}

# web https
server {
    listen 443 ssl http2;
    server_name localhost;

    client_max_body_size 1024m;

    ssl_certificate     /etc/nginx/ssl/test.crt;
    ssl_certificate_key /etc/nginx/ssl/test.key;
    ssl_protocols       tlsv1.2 tlsv1.3;
    ssl_ciphers         high:!anull:!md5;

    location / {
        root /var/www/test-web;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location /test/ {
        proxy_pass http://192.168.2.67:9652;
        proxy_http_version 1.1;
        proxy_set_header connection "";
        proxy_set_header host $host;
        proxy_set_header x-real-ip $remote_addr;
    }
}

# app http → https
server {
    listen 3000;
    server_name localhost;
    return 301 https://$server_name:3001$request_uri;
}

# app https
server {
    listen 3001 ssl http2;
    server_name localhost;

    client_max_body_size 1024m;

    ssl_certificate     /etc/nginx/ssl/test.crt;
    ssl_certificate_key /etc/nginx/ssl/test.key;
    ssl_protocols       tlsv1.2 tlsv1.3;
    ssl_ciphers         high:!anull:!md5;

    location / {
        root /var/www/test-app;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    location /test/ {
        proxy_pass http://192.168.2.67:9652;
        proxy_http_version 1.1;
        proxy_set_header connection "";
        proxy_set_header host $host;
        proxy_set_header x-real-ip $remote_addr;
    }
}

测试配置文件:nginx -t

7. 注册服务并启动 nginx

创建服务文件:
vim /etc/systemd/system/nginx.service
写入以下内容:

[unit]
description=the nginx http and reverse proxy server
after=network.target remote-fs.target nss-lookup.target

[service]
type=forking
pidfile=/run/nginx.pid
# nginx will fail to start if /run/nginx.pid already exists but has the wrong
# selinux context. this might happen when running `nginx -t` from the cmdline.
execstartpre=/usr/bin/rm -f /run/nginx.pid
execstartpre=/usr/sbin/nginx -t
execstart=/usr/sbin/nginx
execreload=/bin/kill -s hup $mainpid
killsignal=sigquit
timeoutstopsec=5
killmode=mixed
privatetmp=true

[install]
wantedby=multi-user.target

设置开机启动并启动 nginx:

systemctl enable nginx
systemctl start nginx
systemctl status nginx

8. 开放防火墙端口

sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --add-port=443/tcp --permanent
sudo firewall-cmd --add-port=3000/tcp --permanent
sudo firewall-cmd --add-port=3001/tcp --permanent
sudo firewall-cmd --reload

9. 访问测试

web 站点:
http://localhost 会自动跳转到 https://localhost
https://localhost 显示 web index

app 站点:
http://localhost:3000 会跳转到 https://localhost:3001
https://localhost:3001 显示 app index

10. 总结

本文介绍了在银河麒麟 v10 系统中 离线安装 nginx 的全过程,包括:

通过该流程,即使在无外网环境下,也能在 kylin os 上快速部署 nginx 服务器。

到此这篇关于银河麒麟(kylin)离线安装nginx并部署多服务完整步骤的文章就介绍到这了,更多相关银河麒麟离线安装nginx部署多服务内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

您想发表意见!!点此发布评论

推荐阅读

Nginx部署前端项目实战指南及常见错误

02-07

解决Redis缓存击穿问题(互斥锁、逻辑过期)

02-07

Redis slowlog使用和实现

02-06

Redis分布式限流生产环境落地方案

02-06

Redis Cluster 实现多key事务操作的示例

02-06

Redis框架在项目中的实战

02-10

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论