
掌握API建模:基本概念和實(shí)踐
??注:阿里云的服務(wù)器記得配置安全組和端口開(kāi)放規(guī)則
也可以不升級(jí),個(gè)人習(xí)慣,畢竟有些包或者依賴最新的還是更好的
[rootenine~]#cat/etc/centos-reLease
CentosLinuxrelease7.8.2003(Core)
當(dāng)前系統(tǒng)版本 7.8.2003
# 查詢centos IP地址
$ ip addr
vi /etc/sysconfig/network-scripts/ifcfg-ens33
###原數(shù)據(jù)###
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="8bc76d14-7d23-4e7a-ba30-d0a8a4ccd0ca"
DEVICE="ens33"
ONBOOT="yes"
###修改后###
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="8bc76d14-7d23-4e7a-ba30-d0a8a4ccd0ca"
DEVICE="ens33"
ONBOOT="yes"
+ BOOTPROTO="static" #設(shè)置為靜態(tài)IP模式
+ IPADDR=192.168.2.99 #IP
+ NETMASK=255.255.255.0 #子網(wǎng)掩碼
+ GATEWAY=192.168.2.1 #網(wǎng)關(guān)
+ DNS1=192.168.2.1 #DNS
+ DNS2=8.8.8.8
增加以下內(nèi)容
BOOTPROTO="static" #設(shè)置為靜態(tài)IP模式
IPADDR=192.168.2.99 #IP地址
NETMASK=255.255.255.0 #子網(wǎng)掩碼
GATEWAY=192.168.2.1 #默認(rèn)網(wǎng)關(guān)
DNS1=192.168.2.1 #DNS1
DNS2=8.8.8.8 #DNS2
systemctl restart network.service #重啟網(wǎng)絡(luò)服務(wù)
systemctl status network.service #查看網(wǎng)絡(luò)服務(wù)狀態(tài)
# 查看系統(tǒng)版本
$ cat /etc/centos-release
CentOS Linux release 7.8.2003 (Core)
Anolis-8.4
cat /etc/anolis-release
Anolis OS release 8.4
$ uname -a
Linux nine 4.18.0-305.an8.x86_64 #1 SMP Sun Jun 20 14:13:18 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
$ uname -r
4.18.0-305.an8.x86_64
# 更新系統(tǒng)
$ sudo yum update
# 更新完查看下系統(tǒng)版本
$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
$ cat /etc/anolis-release
Anolis OS release 8.5
??Docker-ce安裝命令
# 按順序執(zhí)行以下命令
# 卸載清理系統(tǒng)Docker,檢查系統(tǒng)是否自帶,或者別的docker版本,執(zhí)行下卸載命令檢查
$ sudo yum remove docker-ce
# 安裝必要依賴
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 設(shè)置Docker源,這里使用的是阿里云的源,比官方的快一點(diǎn)
$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 更新并安裝Docker-CE
$ sudo yum makecache fast
$ sudo yum -y install docker-ce
# 開(kāi)啟Docker服務(wù)
$ sudo service docker start
# 設(shè)置docker開(kāi)機(jī)啟動(dòng)
$ systemctl enable docker
# 啟動(dòng)Docker
$ systemctl start docker
# 檢查Docker版本
$ docker --version
[root@nine ~]# docker --version
Docker version 20.10.17, build 100c701
$ docker version
[root@nine ~]# docker --version
Docker version 20.10.17, build 100c701
[root@nine ~]# docker version
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:05:12 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:03:33 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.7
GitCommit: 0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb
runc:
Version: 1.1.3
GitCommit: v1.1.3-0-g6724737
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker 安裝結(jié)束,接下來(lái)喜聞樂(lè)見(jiàn)的 Hello word
補(bǔ)充:
yum list docker-ce --showduplicates | sort -r
sudo yum -y install docker-ce-3:19.03.13-3.el8 -y
查看狀態(tài)
systemctl status docker.service
查看版本
docker version
檢測(cè)是否啟動(dòng)成功,可以使用search命令
docker search mysql
systemctl daemon-reload
systemctl restart docker.service
[root@nine ~]# sudo yum remove docker-ce
未找到匹配的參數(shù): docker-ce
沒(méi)有軟件包需要移除。
依賴關(guān)系解決。
無(wú)需任何處理。
完畢!
[root@nine ~]# sudo service docker start
Redirecting to /bin/systemctl start docker.service
[root@nine ~]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@nine ~]# systemctl start docker
[root@nine ~]# docker --version
Docker version 20.10.15, build fd82621
[root@nine ~]# dockerd --debug
INFO[2022-05-09T10:49:00.832071693+08:00] Starting up
failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
[root@nine ~]#
解決 RPM 數(shù)據(jù)庫(kù)損壞的問(wèn)題
刪除損壞的rpmdb文件
$ rm /var/lib/rpm/__**
$ rpm --rebuilddb
$ yum clean all
[root@nine ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
上次元數(shù)據(jù)過(guò)期檢查:0:19:04 前,執(zhí)行于 2022年05月09日 星期一 10時(shí)19分07秒。
Module yaml error: Encountered two streams with matching NSVCA virt-devel:an:8050020220504025225:bc14a129:x86_64 but differing content
Module yaml error: Encountered two streams with matching NSVCA virt-devel:an:8050020220504025225:bc14a129:x86_64 but differing content
軟件包 device-mapper-persistent-data-0.9.0-4.an8.x86_64 已安裝。
軟件包 lvm2-8:2.03.12-10.0.1.an8.x86_64 已安裝。
依賴關(guān)系解決。
============================================================================================================================================================================================================================================================================================
軟件包 架構(gòu) 版本 倉(cāng)庫(kù) 大小
============================================================================================================================================================================================================================================================================================
安裝:
yum-utils noarch 4.0.21-4.0.1.an8 BaseOS 72 k
事務(wù)概要
============================================================================================================================================================================================================================================================================================
安裝 1 軟件包
總下載:72 k
安裝大?。?3 k
下載軟件包:
yum-utils-4.0.21-4.0.1.an8.noarch.rpm 272 kB/s | 72 kB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計(jì) 271 kB/s | 72 kB 00:00
運(yùn)行事務(wù)檢查
事務(wù)檢查成功。
運(yùn)行事務(wù)測(cè)試
事務(wù)測(cè)試成功。
運(yùn)行事務(wù)
RPM軟件包: 錯(cuò)誤:db5 錯(cuò)誤(-30969) 源自 dbenv->open:BDB0091 DB_VERSION_MISMATCH: Database environment version mismatch
RPM軟件包: 錯(cuò)誤:cannot open Packages index using db5 - (-30969)
RPM軟件包: 錯(cuò)誤:無(wú)法從 /var/lib/rpm 打開(kāi)軟件包數(shù)據(jù)庫(kù)
下載的軟件包保存在緩存中,直到下次成功執(zhí)行事務(wù)。
您可以通過(guò)執(zhí)行 'yum clean packages' 刪除軟件包緩存。
錯(cuò)誤:不能執(zhí)行事務(wù)。
[root@nine ~]# rm /var/lib/rpm/__**
rm:是否刪除普通文件 '/var/lib/rpm/__db.001'?y
rm:是否刪除普通文件 '/var/lib/rpm/__db.002'?y
rm:是否刪除普通文件 '/var/lib/rpm/__db.003'?y
[root@nine ~]# rpm --rebuilddb
[root@nine ~]# yum clean all
33 文件已刪除
[root@nine ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
AnolisOS-8 - AppStream 3.6 MB/s | 8.7 MB 00:02
AnolisOS-8 - BaseOS 3.2 MB/s | 4.5 MB 00:01
AnolisOS-8 - Extras 5.0 kB/s | 1.6 kB 00:00
AnolisOS-8 - PowerTools 4.3 MB/s | 2.2 MB 00:00
Module yaml error: Encountered two streams with matching NSVCA virt-devel:an:8050020220504025225:bc14a129:x86_64 but differing content
Module yaml error: Encountered two streams with matching NSVCA virt-devel:an:8050020220504025225:bc14a129:x86_64 but differing content
軟件包 device-mapper-persistent-data-0.9.0-4.an8.x86_64 已安裝。
軟件包 lvm2-8:2.03.12-10.0.1.an8.x86_64 已安裝。
依賴關(guān)系解決。
============================================================================================================================================================================================================================================================================================
軟件包 架構(gòu) 版本 倉(cāng)庫(kù) 大小
============================================================================================================================================================================================================================================================================================
安裝:
yum-utils noarch 4.0.21-4.0.1.an8 BaseOS 72 k
事務(wù)概要
============================================================================================================================================================================================================================================================================================
安裝 1 軟件包
總下載:72 k
安裝大?。?3 k
下載軟件包:
yum-utils-4.0.21-4.0.1.an8.noarch.rpm 448 kB/s | 72 kB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計(jì) 444 kB/s | 72 kB 00:00
運(yùn)行事務(wù)檢查
事務(wù)檢查成功。
運(yùn)行事務(wù)測(cè)試
事務(wù)測(cè)試成功。
運(yùn)行事務(wù)
準(zhǔn)備中 : 1/1
安裝 : yum-utils-4.0.21-4.0.1.an8.noarch 1/1
運(yùn)行腳本: yum-utils-4.0.21-4.0.1.an8.noarch 1/1
驗(yàn)證 : yum-utils-4.0.21-4.0.1.an8.noarch 1/1
已安裝:
yum-utils-4.0.21-4.0.1.an8.noarch
完畢!
[root@nine ~]# sudo yum makecache fast
usage: yum makecache [-c [config file]] [-q] [-v] [--version]
[--installroot [path]] [--nodocs] [--noplugins]
[--enableplugin [plugin]] [--disableplugin [plugin]]
[--releasever RELEASEVER] [--setopt SETOPTS]
[--skip-broken] [-h] [--allowerasing] [-b | --nobest]
[-C] [-R [minutes]] [-d [debug level]] [--debugsolver]
[--showduplicates] [-e ERRORLEVEL] [--obsoletes]
[--rpmverbosity [debug level name]] [-y] [--assumeno]
[--enablerepo [repo]] [--disablerepo [repo] | --repo
[repo]] [--enable | --disable] [-x [package]]
[--disableexcludes [repo]] [--repofrompath [repo,path]]
[--noautoremove] [--nogpgcheck] [--color COLOR]
[--refresh] [-4] [-6] [--destdir DESTDIR]
[--downloadonly] [--comment COMMENT] [--bugfix]
[--enhancement] [--newpackage] [--security]
[--advisory ADVISORY] [--bz BUGZILLA] [--cve CVES]
[--sec-severity {Critical,Important,Moderate,Low}]
[--forcearch ARCH] [--timer]
yum makecache: error: argument timer: invalid choice: 'fast' (choose from 'timer')
### yum makecache: error: argument timer: invalid choice: ‘fast’ (choose from ‘timer’)
在使用yum makecache fast報(bào)錯(cuò)yum makecache: error: argument timer: invalid choice: ‘fast’ (choose from ‘timer’),是因?yàn)镃entOS 8沒(méi)有fast這個(gè)命令 去掉就可以了
阿里云OS注意事項(xiàng)
??注:阿里云OS(Alibaba Cloud Linux release 3)請(qǐng)參考官方文檔,不能直接使用上面語(yǔ)句安裝Docker-ce,很多源被限制了
出錯(cuò)示例
輸入 :$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 安裝報(bào)錯(cuò)----------------------------------------------------
dockerErrors during downloading metadata for repository 'docker-ce-stable':- Status code: 404 for
https://download.docker.com/linux/centos/3/x86_64/stable/repodata/repomd.xml (IP: 13.249.162.1)
# 安裝報(bào)錯(cuò)----------------------------------------------------
# 解決方案----------------------------------------------------
$ cd /etc/yum.repos.d/
$ rm -rf docker-ce.repo
# 解決方案----------------------------------------------------
之后參照這個(gè)文檔安裝Docker-ce
https://help.aliyun.com/document_detail/264695.html?spm=5176.21213303.J_6028563670.38.3acf3eda1H4cBI&scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%40264695.S_hot.ID_264695-RL_docker%E5%AE%89%E8%A3%85-OR_s%2Bhelpmain-V_1-P0_7
??Net Core SDK 沖突注意事項(xiàng)
??注:Docker-ce與Net Core SDK的沖突
安裝docker和net core SDK的順序不同會(huì)有一些別的問(wèn)題,由于微軟下的docker源換掉了,
先安裝SDK會(huì)導(dǎo)致一些組件錯(cuò)誤,也有解決方法,最簡(jiǎn)單的就是先安裝docker再安裝SDK
●先安裝Docker在安裝SDK
可以順利安裝無(wú)需解決
●先安裝SDK再安裝Docker
1. 找到這個(gè)目錄(/etc/yum.repos.d/microsoft-prod.repo)下的進(jìn)入microsoft-prod.repo
2. 備份文件microsoft-prod.repo
3. 然后刪除掉文件microsoft-prod.repo
4. 安裝Docker
5. 還原文件microsoft-prod.repo
測(cè)試Docker
?? 檢查Docker是否可以正常運(yùn)行
運(yùn)行hello-world鏡像,如果本機(jī)沒(méi)有hello-world鏡像,系統(tǒng)會(huì)自動(dòng)拉取hello-world鏡像
$ docker run hello-world
檢查服務(wù)器有什么鏡像
檢查服務(wù)器有什么容器
docker 容器ID:05d58bcbbf33,3分鐘前創(chuàng)建于鏡像hello-word;狀態(tài):已退出
至此,Docker安裝與基礎(chǔ)使用已經(jīng)完成,接下來(lái)開(kāi)始Nginx的安裝和基礎(chǔ)使用
Nginx 是一個(gè)很強(qiáng)大的高性能Web和反向代理服務(wù),它具有很多非常優(yōu)越的特性:
在連接高并發(fā)的情況下,Nginx是Apache服務(wù)不錯(cuò)的替代品。能夠支持高達(dá) 50,000 個(gè)并發(fā)連接數(shù)的響應(yīng)。
?? 安裝Nginx命令
# 安裝Nginx 工具
$ sudo yum install nginx
# 安裝報(bào)錯(cuò)----------------------------------------------------
沒(méi)有可用軟件包 nginx。
錯(cuò)誤:無(wú)須任何處理
# 安裝報(bào)錯(cuò)----------------------------------------------------
原因是nginx位于第三方的yum源里面,而不在centos官方y(tǒng)um源里面
# 報(bào)錯(cuò)處理----------------------------------------------------
# 安裝第三方y(tǒng)um源
$ sudo yum install epel-release
# 更新系統(tǒng)(更新時(shí)間稍微長(zhǎng)一些,耐心等待)
$ yum update
# 報(bào)錯(cuò)處理----------------------------------------------------
# 啟用nginx
$ sudo systemctl enable nginx
# 啟動(dòng)nginx服務(wù)
$ sudo systemctl start nginx
[root@nine ~]# sudo systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@nine ~]# sudo systemctl start nginx
[root@nine ~]#
至此,Nginx安裝完成,可以繼續(xù)下一步?? Docker 部署方案,學(xué)習(xí)Docker部署 (Nginx 常用命令 反向代理配置demo負(fù)載均衡 動(dòng)靜分離 限流跨域 高并發(fā))這幾個(gè)知識(shí)點(diǎn)的梳理可以后續(xù)學(xué)習(xí) ,非本文重點(diǎn)
?? Nginx 常用命令
# 顯示版本信息
$ nginx -v
# 顯示版本和配置項(xiàng)信息
$ nginx -V
# 測(cè)試配置文件是否存在語(yǔ)法問(wèn)題
$ nginx -t
# 測(cè)試配置文件,轉(zhuǎn)儲(chǔ)并退出
$ nginx -T
# 檢測(cè)配制間時(shí)屏蔽非錯(cuò)誤信息,只輸出錯(cuò)誤信息
$ nginx -q
# 重新打開(kāi)日志文件
$ nginx -s reopen
# 快速停止Nginx,此方法是先查看nginx主進(jìn)程號(hào)然后再使用kill 強(qiáng)制殺掉
$ nginx -s stop
# 優(yōu)雅退出Nginx (推薦使用,此方法會(huì)等待Nginx進(jìn)程處理完畢再停止)
$ nginx -s quit
# 重新加載配置并且啟動(dòng)
$ nginx -s reload
# 內(nèi)置變量這塊主要用于日志
$http_ referer :用來(lái)記錄客戶從哪個(gè)頁(yè)面鏈接訪問(wèn)過(guò)來(lái)的
$http_ _user agent :用來(lái)記錄客戶流量相關(guān)信息
$remote_ addr和Shttp. x forwarded. for :用來(lái)記錄客戶端ip地址
$http_ user :用來(lái)記錄客戶端的用戶名稱
$request :用來(lái)記錄請(qǐng)求的URL和HTTP協(xié)議
$status :用來(lái)記錄請(qǐng)求狀態(tài)
$body. bytes. sent: 用來(lái)記錄發(fā)送給客戶端文件主體內(nèi)容大小
?? Nginx/1.20.1默認(rèn)配置文件
# nginx默認(rèn)配置文件路徑
$ cd /ect/nginx --nginx.conf
$ vi /ect/nginx/nginx.conf
--------------------以下默認(rèn)配置文件-------------------------------
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
?? 反向代理配置demo
http {
server {
listen 80;
server_name localhost;
……
location / {
root html;
index index.html index.htm;
}
# 路由到商品服務(wù)
location /api-product {
proxy_pass http://localhost:8081/;
}
# 路由到訂單服務(wù)
location /api-order {
proxy_pass http://localhost:8082/;
}
}
}
---------------------------實(shí)例--------------------------
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;
client_max_body_size 1000m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
#跨域
#add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE';
#add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
#add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Allow-Headers X-Requested-With;
#add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
keepalive_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 65;
proxy_buffer_size 128k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# 服務(wù)器集群名稱 和下面的location地址對(duì)應(yīng)
upstream DevServer {
# weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大
# server 127.0.0.1:8080 weight=1;
# server 127.0.0.1:8060 weight=1;
ip_hash;
server localhost:5000 weight=10;
server localhost:5001 weight=10;
server localhost:5002 weight=10;
server localhost:5003 weight=10;
server localhost:5004 weight=10;
}
# API-代理配置
server {
# 跨域請(qǐng)求,也可以在程序內(nèi)進(jìn)行配置appsetting.json
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
listen 6007;
#server_name localhost;
location / {
proxy_set_header X-Real-IP Sremote_addr;
proxy_set_header Host $http_host;
proxy_pass http://DevServer;
rewrite ^.+apb/?(.*)$ /$1 break;
include uwsgi_params;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
#proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api2/ {
rewrite ^.+apb/?(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://DevServer;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# 客戶端-代理配置
server {
listen 6008;
location / {
proxy_set_header X-Real-IP Sremote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:2003;
}
location /api/ {
rewrite ^.+apb/?(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://localhost:2003;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
#proxy_set_header Host Shost;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Jenkins CI/CD 代理配置
server {
# 跨域請(qǐng)求,也可以在程序內(nèi)進(jìn)行配置appsetting.json
#add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE';
#add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
listen 6020;
location / {
proxy_set_header X-Real-IP Sremote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8099;
}
location /api/ {
rewrite ^.+apb/?(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://localhost:8099;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
#proxy_set_header Host Shost;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
文章轉(zhuǎn)自微信公眾號(hào)@BCVP代碼創(chuàng)新社
掌握API建模:基本概念和實(shí)踐
程序員常用的API接口管理工具有哪些?
簡(jiǎn)化API縮寫(xiě):應(yīng)用程序編程接口終極指南
如何為你的項(xiàng)目挑選最佳API?完整選擇流程解讀
應(yīng)用程序開(kāi)發(fā)蓬勃發(fā)展的必備開(kāi)放API
.NET Core Web APi類庫(kù)如何內(nèi)嵌運(yùn)行和.NET Core Web API 中的異常處理
優(yōu)化利潤(rùn):計(jì)算并報(bào)告OpenAI支持的API的COGS
用于集成大型語(yǔ)言模型的LLM API
API開(kāi)發(fā)流程:從設(shè)計(jì)到部署的完整指南(含代碼示例)
對(duì)比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力
一鍵對(duì)比試用API 限時(shí)免費(fèi)