介绍
MESH-PLATFORM
是一个全新的软件开发框架。
说明
Debain12
默认安装1.22+
更新APT源Nginx 官方APT 仓库
- 更新源
bash
sudo apt update -y
- 安装依赖工具
bash
sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
- 导入Nginx GPG 密钥
bash
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
- 验证密钥指纹
bash
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
- 添加 Nginx APT 源
bash
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
- 设置仓库优先级(选)
bash
#防止与系统仓库冲突
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900" \
| sudo tee /etc/apt/preferences.d/99nginx
- 更新软件包列表
bash
sudo apt update -y
安装Nginx
- 安装nginx
bash
sudo apt install nginx
- 验证安装
bash
nginx -v
- 启动失败错误日志
bash
sudo tail -n 50 /var/log/nginx/error.log
- 编辑配置文件
bash
#最高级配置
sudo vim /etc/nginx/nginx.conf
#建议个人自定义配置在/conf.d文件下新建配置
cd /etc/nginx/conf.d
sudo vim demo.conf
#示例
server {
listen 80;
server_name 127.0.0.1;
location / {
root /opt/ui/crm;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
# API接口转发
location ^~/pro-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
卸载Nginx
- 停止nginx服务
bash
sudo systemctl stop nginx
- 卸载nginx相关包
bash
sudo apt purge -y nginx nginx-common
sudo apt autoremove -y
- 删除残留数据和配置文件
bash
sudo rm -rf /etc/nginx/
sudo rm -rf /var/www/html/
sudo rm -rf /var/log/nginx/
- 清理APT仓库
bash
sudo rm /etc/apt/sources.list.d/nginx.list
sudo apt update
常用命令
bash
#启动 Nginx
sudo systemctl start nginx
#停止 Nginx
sudo systemctl stop nginx
#重启 Nginx
sudo systemctl restart nginx
#查看 Nginx 状态
sudo systemctl status nginx
#开机 Nginx 自启
sudo systemctl enable nginx
#验证 Nginx
sudo nginx -t