??注:阿里云的服務器記得配置安全組和端口開放規則


?? 1.2 Cent OS系統升級


也可以不升級,個人習慣,畢竟有些包或者依賴最新的還是更好的

[rootenine~]#cat/etc/centos-reLease

CentosLinuxrelease7.8.2003(Core)

當前系統版本 7.8.2003

# 查詢centos IP地址
$ ip addr
vi /etc/sysconfig/network-scripts/ifcfg-ens33
###原數據###
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" #設置為靜態IP模式
+ IPADDR=192.168.2.99 #IP
+ NETMASK=255.255.255.0 #子網掩碼
+ GATEWAY=192.168.2.1 #網關
+ DNS1=192.168.2.1 #DNS
+ DNS2=8.8.8.8

增加以下內容

BOOTPROTO="static" #設置為靜態IP模式
IPADDR=192.168.2.99 #IP地址
NETMASK=255.255.255.0 #子網掩碼
GATEWAY=192.168.2.1 #默認網關
DNS1=192.168.2.1 #DNS1
DNS2=8.8.8.8 #DNS2

systemctl restart network.service #重啟網絡服務
systemctl status network.service #查看網絡服務狀態
# 查看系統版本
$ 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

# 更新系統
$ sudo yum update

# 更新完查看下系統版本
$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
$ cat /etc/anolis-release
Anolis OS release 8.5

?? 1.3 Docker 基礎使用與安裝


? 安裝Docker-ce(Cent OS 7)


??Docker-ce安裝命令

# 按順序執行以下命令

# 卸載清理系統Docker,檢查系統是否自帶,或者別的docker版本,執行下卸載命令檢查
$ sudo yum remove docker-ce

# 安裝必要依賴
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

# 設置Docker源,這里使用的是阿里云的源,比官方的快一點
$ 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

# 開啟Docker服務
$ sudo service docker start

# 設置docker開機啟動
$ systemctl enable docker

# 啟動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 安裝結束,接下來喜聞樂見的 Hello word

補充:
yum list docker-ce --showduplicates | sort -r
sudo yum -y install docker-ce-3:19.03.13-3.el8 -y
查看狀態
systemctl status docker.service
查看版本
docker version
檢測是否啟動成功,可以使用search命令
docker search mysql

systemctl daemon-reload
systemctl restart docker.service

[root@nine ~]# sudo yum remove docker-ce
未找到匹配的參數: docker-ce
沒有軟件包需要移除。
依賴關系解決。
無需任何處理。
完畢!
[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 數據庫損壞的問題
刪除損壞的rpmdb文件
$ rm /var/lib/rpm/__**
$ rpm --rebuilddb
$ yum clean all

[root@nine ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
上次元數據過期檢查:0:19:04 前,執行于 2022年05月09日 星期一 10時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 已安裝。
依賴關系解決。
============================================================================================================================================================================================================================================================================================
軟件包 架構 版本 倉庫 大小
============================================================================================================================================================================================================================================================================================
安裝:
yum-utils noarch 4.0.21-4.0.1.an8 BaseOS 72 k

事務概要
============================================================================================================================================================================================================================================================================================
安裝 1 軟件包

總下載:72 k
安裝大?。?3 k
下載軟件包:
yum-utils-4.0.21-4.0.1.an8.noarch.rpm 272 kB/s | 72 kB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計 271 kB/s | 72 kB 00:00
運行事務檢查
事務檢查成功。
運行事務測試
事務測試成功。
運行事務
RPM軟件包: 錯誤:db5 錯誤(-30969) 源自 dbenv->open:BDB0091 DB_VERSION_MISMATCH: Database environment version mismatch
RPM軟件包: 錯誤:cannot open Packages index using db5 - (-30969)
RPM軟件包: 錯誤:無法從 /var/lib/rpm 打開軟件包數據庫
下載的軟件包保存在緩存中,直到下次成功執行事務。
您可以通過執行 'yum clean packages' 刪除軟件包緩存。
錯誤:不能執行事務。
[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 已安裝。
依賴關系解決。
============================================================================================================================================================================================================================================================================================
軟件包 架構 版本 倉庫 大小
============================================================================================================================================================================================================================================================================================
安裝:
yum-utils noarch 4.0.21-4.0.1.an8 BaseOS 72 k

事務概要
============================================================================================================================================================================================================================================================================================
安裝 1 軟件包

總下載:72 k
安裝大小:23 k
下載軟件包:
yum-utils-4.0.21-4.0.1.an8.noarch.rpm 448 kB/s | 72 kB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計 444 kB/s | 72 kB 00:00
運行事務檢查
事務檢查成功。
運行事務測試
事務測試成功。
運行事務
準備中 : 1/1
安裝 : yum-utils-4.0.21-4.0.1.an8.noarch 1/1
運行腳本: yum-utils-4.0.21-4.0.1.an8.noarch 1/1
驗證 : 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報錯yum makecache: error: argument timer: invalid choice: ‘fast’ (choose from ‘timer’),是因為CentOS 8沒有fast這個命令 去掉就可以了

阿里云OS注意事項
??注:阿里云OS(Alibaba Cloud Linux release 3)請參考官方文檔,不能直接使用上面語句安裝Docker-ce,很多源被限制了

出錯示例

輸入 :$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 安裝報錯----------------------------------------------------
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)
# 安裝報錯----------------------------------------------------

# 解決方案----------------------------------------------------
$ cd /etc/yum.repos.d/
$ rm -rf docker-ce.repo
# 解決方案----------------------------------------------------

之后參照這個文檔安裝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  沖突注意事項
??注:Docker-ce與Net Core SDK的沖突
安裝docker和net core SDK的順序不同會有一些別的問題,由于微軟下的docker源換掉了,
先安裝SDK會導致一些組件錯誤,也有解決方法,最簡單的就是先安裝docker再安裝SDK
●先安裝Docker在安裝SDK
可以順利安裝無需解決

●先安裝SDK再安裝Docker

 1. 找到這個目錄(/etc/yum.repos.d/microsoft-prod.repo)下的進入microsoft-prod.repo
2. 備份文件microsoft-prod.repo
3. 然后刪除掉文件microsoft-prod.repo
4. 安裝Docker
5. 還原文件microsoft-prod.repo

測試Docker
?? 檢查Docker是否可以正常運行
運行hello-world鏡像,如果本機沒有hello-world鏡像,系統會自動拉取hello-world鏡像

  $ docker run hello-world

檢查服務器有什么鏡像

檢查服務器有什么容器

docker 容器ID:05d58bcbbf33,3分鐘前創建于鏡像hello-word;狀態:已退出

至此,Docker安裝與基礎使用已經完成,接下來開始Nginx的安裝和基礎使用


?? 1.4 Nginx 基礎使用與安裝


Nginx 是一個很強大的高性能Web和反向代理服務,它具有很多非常優越的特性:
在連接高并發的情況下,Nginx是Apache服務不錯的替代品。能夠支持高達 50,000 個并發連接數的響應。


? 重點–反向代理

?? 安裝Nginx命令

# 安裝Nginx 工具
$ sudo yum install nginx

# 安裝報錯----------------------------------------------------
沒有可用軟件包 nginx。
錯誤:無須任何處理
# 安裝報錯----------------------------------------------------

原因是nginx位于第三方的yum源里面,而不在centos官方yum源里面

# 報錯處理----------------------------------------------------
# 安裝第三方yum源
$ sudo yum install epel-release
# 更新系統(更新時間稍微長一些,耐心等待)
$ yum update
# 報錯處理----------------------------------------------------

# 啟用nginx
$ sudo systemctl enable nginx

# 啟動nginx服務
$ 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安裝完成,可以繼續下一步?? Docker 部署方案,學習Docker部署   (Nginx 常用命令 反向代理配置demo負載均衡 動靜分離 限流跨域 高并發)這幾個知識點的梳理可以后續學習 ,非本文重點
?? Nginx 常用命令

# 顯示版本信息
$ nginx -v
# 顯示版本和配置項信息
$ nginx -V
# 測試配置文件是否存在語法問題
$ nginx -t
# 測試配置文件,轉儲并退出
$ nginx -T
# 檢測配制間時屏蔽非錯誤信息,只輸出錯誤信息
$ nginx -q
# 重新打開日志文件
$ nginx -s reopen
# 快速停止Nginx,此方法是先查看nginx主進程號然后再使用kill 強制殺掉
$ nginx -s stop
# 優雅退出Nginx (推薦使用,此方法會等待Nginx進程處理完畢再停止)
$ nginx -s quit
# 重新加載配置并且啟動
$ nginx -s reload

# 內置變量這塊主要用于日志
$http_ referer :用來記錄客戶從哪個頁面鏈接訪問過來的
$http_ _user agent :用來記錄客戶流量相關信息
$remote_ addr和Shttp. x forwarded. for :用來記錄客戶端ip地址
$http_ user :用來記錄客戶端的用戶名稱
$request :用來記錄請求的URL和HTTP協議
$status :用來記錄請求狀態
$body. bytes. sent: 用來記錄發送給客戶端文件主體內容大小

?? Nginx/1.20.1默認配置文件

# nginx默認配置文件路徑
$ cd /ect/nginx --nginx.conf
$ vi /ect/nginx/nginx.conf

--------------------以下默認配置文件-------------------------------
# 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;
}
# 路由到商品服務
location /api-product {
proxy_pass http://localhost:8081/;
}
# 路由到訂單服務
location /api-order {
proxy_pass http://localhost:8082/;
}
}
}

---------------------------實例--------------------------
# 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 {
}
}

# 服務器集群名稱 和下面的location地址對應
upstream DevServer {
# weigth參數表示權值,權值越高被分配到的幾率越大
# 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 {

# 跨域請求,也可以在程序內進行配置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 {
# 跨域請求,也可以在程序內進行配置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 {
# }
# }

}

?知識點梳理–負載均衡

?知識點梳理–動靜分離

?知識點梳理–限流/跨域

?知識點梳理–高并發解決方案

文章轉自微信公眾號@BCVP代碼創新社

上一篇:

Amazon的API描述語言Smithy概述

下一篇:

.NetCore之WebApi接口裸奔有風險(Jwt)
#你可能也喜歡這些API文章!

我們有何不同?

API服務商零注冊

多API并行試用

數據驅動選型,提升決策效率

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

對比大模型API的內容創意新穎性、情感共鳴力、商業轉化潛力

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費