[GH-ISSUE #261] Get 403 Forbidden when proxy by nginx #12009

Closed
opened 2026-04-19 18:44:14 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @lingen on GitHub (Dec 22, 2023).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/261

I just want to proxy ollama-webui by nginx.
And there is the config


server
{
	listen 3389;
	server_name ai.myai.com;

	location /
	{

		proxy_redirect off;
		proxy_pass http://127.0.0.1:8082;
		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;
		proxy_next_upstream off;


	}
}

Also, I started the ollama-webui in docker.

docker run -d -p 8082:8080 --add-host=host.docker.internal:host-gateway --name ollama-webui --restart always ghcr.io/ollama-webui/ollama-webui:main

In fact, When I started ollama-webui in the 3389 port, everything was ok. But when I proxy it by nginx, there is a 403 Forbidden error.

Do anyone know what the problems are?

image
Originally created by @lingen on GitHub (Dec 22, 2023). Original GitHub issue: https://github.com/open-webui/open-webui/issues/261 I just want to proxy ollama-webui by nginx. And there is the config ```nginx server { listen 3389; server_name ai.myai.com; location / { proxy_redirect off; proxy_pass http://127.0.0.1:8082; 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; proxy_next_upstream off; } } ``` Also, I started the ollama-webui in docker. ```shell docker run -d -p 8082:8080 --add-host=host.docker.internal:host-gateway --name ollama-webui --restart always ghcr.io/ollama-webui/ollama-webui:main ``` In fact, When I started ollama-webui in the 3389 port, everything was ok. But when I proxy it by nginx, there is a 403 Forbidden error. Do anyone know what the problems are? <img width="644" alt="image" src="https://github.com/ollama-webui/ollama-webui/assets/2062865/ca43686d-86e9-4742-8b1f-baae2fa9d9ed">
Author
Owner

@oliverbob commented on GitHub (Dec 23, 2023):

Have you tried doing it with this Apache proxy example?

<!-- gh-comment-id:1868219319 --> @oliverbob commented on GitHub (Dec 23, 2023): Have you tried doing it with this [Apache proxy example](https://github.com/ollama-webui/ollama-webui/issues/256)?
Author
Owner

@lingen commented on GitHub (Dec 25, 2023):

Thank you very much. I will try it.

<!-- gh-comment-id:1868659500 --> @lingen commented on GitHub (Dec 25, 2023): Thank you very much. I will try it.
Author
Owner

@lingen commented on GitHub (Dec 25, 2023):

@oliverbob

OK, I solve this problem.

The blew config of the Nginx proxy is ok.

server {
    listen 3389;
    server_name ai.myai.com;

    location / {
      proxy_pass http://127.0.0.1:8082;

    }

    location /ollama/api {
      proxy_buffering off;
      proxy_set_header Origin '';
      proxy_set_header Referer '';
      proxy_pass http://127.0.0.1:11434/api;

    }

    location /api/v1 {
     proxy_pass http://127.0.0.1:8082/api/v1;
    }
}

And there two lines are very important

      proxy_set_header Origin '';
      proxy_set_header Referer '';

But I have no idea why this happened. And I thought this was not Ollama-webui's problem. Maybe it's ollama server's problem.

Because the 403 error is generated by Ollama Server but not Ollama-webui.

Thanks. I appreciate your help.

<!-- gh-comment-id:1868683804 --> @lingen commented on GitHub (Dec 25, 2023): @oliverbob OK, I solve this problem. The blew config of the Nginx proxy is ok. ```nginx server { listen 3389; server_name ai.myai.com; location / { proxy_pass http://127.0.0.1:8082; } location /ollama/api { proxy_buffering off; proxy_set_header Origin ''; proxy_set_header Referer ''; proxy_pass http://127.0.0.1:11434/api; } location /api/v1 { proxy_pass http://127.0.0.1:8082/api/v1; } } ``` And there two lines are very important ```shell proxy_set_header Origin ''; proxy_set_header Referer ''; ``` But I have no idea why this happened. And I thought this was not Ollama-webui's problem. Maybe it's ollama server's problem. Because the 403 error is generated by Ollama Server but not Ollama-webui. Thanks. I appreciate your help.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#12009