銀河麒麟(Kylin)離線安裝Nginx并部署多服務(wù)完整步驟
本文介紹如何在 銀河麒麟操作系統(tǒng)(Kylin V10)上進(jìn)行 Nginx 的離線安裝與配置,包括依賴包下載、HTTPS 配置、多端口站點(diǎn)部署等完整步驟。
1. 準(zhǔn)備環(huán)境
由于是離線安裝,需要提前下載 Nginx 及其依賴的 RPM 包。
銀河麒麟官方鏡像地址示例:https://update.cs2c.com.cn/NS/V10/V10SP3/os/adv/lic/updates/x86_64/Packages/
其中
V10、V10SP3、x86_64根據(jù)你的系統(tǒng)版本和 CPU 架構(gòu)調(diào)整。
需要下載以下 RPM 包(注意版本匹配):
gperftools-libs-.......rpmnghttp2-.......rpmnginx-.......rpmnginx-all-modules-.......rpmnginx-filesystem-.......rpmopenssl-.......rpmopenssl-libs-.......rpmpcre2-.......rpmzlib-.......rpm
2. 安裝 Nginx 及依賴
將下載好的 RPM 包放到 /tmp/nginx_rpm/ 目錄:
cd /tmp/nginx_rpm/ rpm -ivh *.rpm --force --nodeps
3. 生成 SSL 證書
創(chuàng)建證書目錄:
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. 創(chuàng)建測(cè)試站點(diǎn)目錄
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(替換原內(nèi)容):
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. 新建多站點(diǎn)配置文件
新建 /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;
}
}
測(cè)試配置文件:nginx -t
7. 注冊(cè)服務(wù)并啟動(dòng) Nginx
創(chuàng)建服務(wù)文件:vim /etc/systemd/system/nginx.service
寫入以下內(nèi)容:
[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
設(shè)置開機(jī)啟動(dòng)并啟動(dòng) 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. 訪問測(cè)試
Web 站點(diǎn):http://localhost 會(huì)自動(dòng)跳轉(zhuǎn)到 https://localhosthttps://localhost 顯示 Web Index
App 站點(diǎn):http://localhost:3000 會(huì)跳轉(zhuǎn)到 https://localhost:3001https://localhost:3001 顯示 App Index
10. 總結(jié)
本文介紹了在銀河麒麟 V10 系統(tǒng)中 離線安裝 Nginx 的全過程,包括:
- 依賴包下載與安裝
- 自簽名 SSL 證書生成
- 多站點(diǎn) HTTPS 配置
- 反向代理示例
- 防火墻端口開放
通過該流程,即使在無外網(wǎng)環(huán)境下,也能在 Kylin OS 上快速部署 Nginx 服務(wù)器。
到此這篇關(guān)于銀河麒麟(Kylin)離線安裝Nginx并部署多服務(wù)完整步驟的文章就介紹到這了,更多相關(guān)銀河麒麟離線安裝Nginx部署多服務(wù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx上對(duì)同一IP訪問的特定URL進(jìn)行限流實(shí)現(xiàn)
要在Nginx上對(duì)同一IP訪問的特定URL進(jìn)行限流,您可以使用ngx_http_limit_req_module模塊,本文就來介紹一下如何使用,具有一定的參考價(jià)值,感興趣的餓2024-01-01
NGINX 報(bào)錯(cuò) 413 Request Entity Too&nbs
本文講述了處理Nginx因接口數(shù)據(jù)量過大導(dǎo)致的413錯(cuò)誤,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-08-08
Nginx可視化管理工具結(jié)合cpolar實(shí)現(xiàn)遠(yuǎn)程訪問的步驟詳解
Nginx Proxy Manager 是一個(gè)開源的反向代理工具,本文將給大家介紹在Linux 安裝Nginx Proxy Manager并且結(jié)合 cpolar內(nèi)網(wǎng)穿透工具實(shí)現(xiàn)遠(yuǎn)程訪問管理界面,同等,當(dāng)我們使用Nginx Proxy Manager配置其他本地服務(wù),并且需要遠(yuǎn)程訪問,也是同樣的方式,需要的朋友可以參考下2023-09-09
HAProxy和Nginx搭建負(fù)載均衡器的實(shí)現(xiàn)
負(fù)載均衡器是一個(gè)常用于分布式計(jì)算和網(wǎng)絡(luò)應(yīng)用中的系統(tǒng)組件,主要用于將客戶端的請(qǐng)求分發(fā)到多個(gè)后端服務(wù)器上,以實(shí)現(xiàn)高可用性、高性能和可擴(kuò)展性,本文主要介紹了HAProxy和Nginx搭建負(fù)載均衡器的實(shí)現(xiàn),感興趣的可以了解一下,感興趣的可以了解一下2023-11-11
windows系統(tǒng)安裝配置nginx環(huán)境
這篇文章介紹了windows系統(tǒng)安裝配置nginx環(huán)境的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
nginx實(shí)現(xiàn)TCP反向代理的示例代碼
本文主要介紹了nginx實(shí)現(xiàn)TCP反向代理的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-01-01

