銀河麒麟(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)建測試站點(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;
}
}
測試配置文件:nginx -t
7. 注冊服務(wù)并啟動 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ī)啟動并啟動 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 站點(diǎn):http://localhost 會自動跳轉(zhuǎn)到 https://localhosthttps://localhost 顯示 Web Index
App 站點(diǎn):http://localhost:3000 會跳轉(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx中反向代理+負(fù)載均衡+服務(wù)器宕機(jī)解決辦法詳解
這篇文章主要介紹了Nginx中反向代理+負(fù)載均衡+服務(wù)器宕機(jī)解決辦法詳解,反向代理保證系統(tǒng)安全,不暴露服務(wù)器IP,利用nginx服務(wù)器,利用內(nèi)網(wǎng)ip進(jìn)行訪問,避免出現(xiàn)攻擊服務(wù)器的情況,需要的朋友可以參考下2024-01-01
nginx正向代理http和https的實(shí)現(xiàn)步驟
本文主要介紹了nginx正向代理http和https的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
基于nginx設(shè)置瀏覽器協(xié)商緩存過程詳解
這篇文章主要介紹了基于nginx設(shè)置瀏覽器協(xié)商緩存過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12

