Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Connecting a Self-Hosted Ollama Server to WordPress (and Why localhost Won’t Work)

说明与用途

为 WordPress 配置本地 Ollama 服务器:更改监听地址、限制访问并测试连接。

问题

WordPress plugins that use Ollama fail to connect when the Ollama server is on a different machine because the plugin uses localhost, which refers to the web server itself.

结果

After configuring Ollama to listen on a reachable address, securing the port, and verifying connectivity from both the shell and PHP, the WordPress plugin can successfully connect to the local LLM and generate content.

工作流

  • Install Ollama and pull a model on the server that will host it.
  • Determine whether Ollama and WordPress share the same machine; if not, configure Ollama to listen on a network address reachable by WordPress (e.g., set OLLAMA_HOST via systemd override).
  • Secure the Ollama port by limiting inbound traffic to the WordPress server using a firewall (e.g., ufw).
  • Test connectivity from the WordPress server’s shell using curl to the Ollama API endpoints.
  • Test connectivity from PHP inside WordPress using wp_remote_post via WP-CLI to ensure the WordPress HTTP API can reach Ollama.
  • Adjust timeouts or model size if requests time out, considering cold starts and hardware limits.
  • Configure the WordPress plugin with the Ollama server URL and model name, then test the connection within the plugin settings.
  • Use the plugin’s workflow to generate content, review, and apply it to posts.

证据

When a WordPress plugin calls http://localhost:11434, the request is made by PHP on the web server. "localhost" means the web server itself, not your laptop.

来源

Ollama’s API has no built-in authentication. Anyone who can reach port 11434 can run prompts on your hardware.

来源

curl http://10.0.0.5:11434/api/tags # Does generation work? curl http://10.0.0.5:11434/api/generate -d '{"model": "llama3.2", "prompt": "Write a page title for a bakery in Leeds.", "stream": false}'

来源

  • 记录日期: 2026-10-21T15:41:20.759Z