96SEO 2026-06-19 03:09 1
在 Mac 上部署大模型并实现远程调用,这事儿听起来好像挺复杂,但咱一步步来哈哈,你就发现其实也没那么难。
第一步:本地部署大模型你得有个大模型,这里咱用 Gemma 为例。

下载并安装 Ollama,过程hen简单,就不多说了。
一条命令搞定模型下载和运行:ollama run gemma4
首次运行会自动下载模型,大小约 5GB,耐心等待哈。
下载完成后你就Ke以在本地跟 Gemma 聊天了输入 /bye 退出。
Ollama 启动后会在 localhost: 提供 HTTP API。
测试一下:curl http://localhost:# 返回: Ollama is running
再试试对话接口:curl -X POST http://localhost:/api/chat \
-H "Content-Type: application/json" \
-d '{"model":"gemma4","messages":,"stream":false}'
Ollama 原生 API 比较底层,咱用 Node.js 封装一层geng友好的 HTTP API,并通过 OrbStack容器化部署。
为啥要用 Docker?方便管理嘛,你懂的。
创建项目目录mkdir ~/gemma4-api && cd ~/gemma4-api
核心代码:const http = require;
const crypto = require;
const OLLAMA_URL = process.env.OLLAMA_URL || "http://host.docker.internal:";
const PORT = process.env.PORT || ; // 你指定的端口
// 内存存储对话历史
const conversations = new Map;
function getOrCreateConversation {
if id = crypto.randomUUID;
if ) {
conversations.set(id, {
id,
messages: ,
createdAt: new Date.toISOString,
updatedAt: new Date.toISOString,
title: "",
});
}
return conversations.get;
}
// 调用 Ollama
async function chatWithOllama {
const res = await fetch(`${OLLAMA_URL}/api/chat`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify,
});
if throw new Error;
return res;
}
const server = http.createServer => {
// CORS 处理
res.setHeader;
res.setHeader;
res.setHeader;
// POST /chat - 核心对话接口
if {
const body = JSON.parse);
const conv = getOrCreateConversation;
conv.messages.push;
if {
// 流式返回
res.writeHead;
const ollamaRes = await chatWithOllama;
// ... 省略逐块写入代码
} else {
// 一次性返回
const ollamaRes = await chatWithOllama;
const data = await ollamaRes.json;
conv.messages.push;
res.end(JSON.stringify({
conversation_id: conv.id,
content: data.message.content
}));
}
}
// 其他路由省略...
});
server.listen;
关键点这里用到了 host.docker.internal 这个特殊的域名,让容器Neng访问宿主机上的 Ollama 服务,hen巧妙,你懂的。
创建 Dockerfile.apiFROM node:-slim
WORKDIR /app
COPY server.js .
EXPOSE
CMD
services:
api:
build:
context: .
dockerfile: Dockerfile.api
container_name: chat-api
ports:
- ":" # 你指定的端口映射
environment:
- OLLAMA_URL=http://host.docker.internal:
- PORT=
restart: unless-stopped
docker compose up -d --build
# 健康检查
curl http://localhost:/health
# 非流式对话
curl -X POST http://localhost:/chat \
-H "Content-Type: application/json" \
-d '{"message":"你好","stream":false}'
# 查kan对话列表
curl http://localhost:/conversations
# 查kan对话详情
curl http://localhost:/conversations/<conversation_id>
Mac 在内网,没有公网 IP,通过 frp 把本地服务暴露到公网服务器,说白了就是“打个洞”。
为什么百度不收录我的文章?这事儿说来话长...通常有几个原因: 1. 网站权重太低新站或小站内容hen难被及时发现。 2. robots.txt 没配置好屏蔽了爬虫。 3. 内容原创性不够大量相似或采集内容。
解决方法嘛: - 提交网站地图 - 主动推送新内容链接 - 多Zuo高质量外链
扯远了咱继续说 frp 配置。
服务端配置
下载 frps 并配置 frps.toml
toml
bindPort =
auth.method = "token"
auth.token = "your-secure-token"
启动 frps:
bash
./frps -c frps.toml
建议用 systemd 管理服务,确保开机自启。
客户端配置
创建 frpc.toml
toml
serverAddr = "." # 公网服务器 IP
serverPort =
auth.method = "token"
auth.token = "your-secure-token"
] name = "gemma4-chat" type = "tcp" localIP = "host.docker.internal" localPort = # chat-api 端口 remotePort = # 公网暴露的端口
启动 frpc:
bash
frpc -c frpc.toml
这样,你的本地服务就“穿透”到公网了!
第四层:Nginx 反向代理裸露 IP + 端口号不安全也不美观,用 Nginx 加上域名和 HTTPS。
安装 Nginx 和 Certbot:
bash
sudo apt update && sudo apt install nginx certbot python-certbot-nginx -y # Ubuntu/Debian 系命令,其他系统类似处理即可。
害,这个过程挺简单的,就是安装两个软件包。
配置反向代理:
创建 /etc/nginx/sites-available/ai.conf,核心内容如下:
nginx
server {
listen ;
server_name ai.yourdomain.com;
location / { proxypass http://.:; # 转发到 frps proxysetheader Host $host; proxysetheader X-Real-IP $remoteaddr; proxysetheader X-Forwarded-For $proxyaddxforwardedfor;
# SSE 流式响应支持
proxy_buffering off;
proxy_cache off;
proxy_read_timeout s;
# WebSocket 支持
proxy_http_version ;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
if { # 简单的安全验证机制,防止滥用接口。
return '{"error":"Unauthorized"}';
}
} }
启用配置: bash sudo ln -s /etc/nginx/sites-available/ai.conf /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx
然后申请 HTTPS :Let's Encrypt证书,hen简单,一条命令搞定自动续期、自动geng新nginx相关配置等工作,具体参见其他文档或搜索引擎相关结果。
至此整条链路就通了从公网通过HTTPS访问,Zui终调用你Mac上的大模型。
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback