본문 바로가기
IT/Etc

ngjinx(https) + Open WebUi + Ollama

by 조병희 2025. 2. 27.

우선은 맥에서 진행.

1. Ollama 설치

1. ollama 사이트에서 다운받아서 설치

2. 모델 다운로드 및 테스트

(base) bhjo0930@Mac-mini-M4 apps % ollama run llama3.2

...

>>> hi.

How can I assist you today?

>>> /bye

3. 혹시 서비스로 시작되어 있지 않으면 실행

(base) bhjo0930@Mac-mini-M4 apps % ollama serve

Error: listen tcp 127.0.0.1:11434: bind: address already in use

(base) bhjo0930@Mac-mini-M4 apps % curl http://localhost:11434/api/tags

{"models":[{"name":"llama3.2:latest","model":"llama3.2:latest","modified_at":"2025-02-26T23:39:36.712756806+09:00","size":2019393189,"digest":"a80c4f17acd55265feec403c7aef86be0c25983ab279d83f3bcd3abbcb5b8b72","details":{"parent_model":"","format":"gguf","family":"llama","families":["llama"],"parameter_size":"3.2B","quantization_level":"Q4_K_M"}}]}%

 

2. Open-Webui 설치

1. 설치 소스 다운로드

(base) bhjo0930@Mac-mini-M4 apps % git clone https://github.com/open-webui/open-webui.git

(base) bhjo0930@Mac-mini-M4 apps % cd open-webui

(base) bhjo0930@Mac-mini-M4 apps % docker compose up -d

 

2. 정상적으로 동작하는지 다시 한번 내렸다 올려본다. 

(base) bhjo0930@Mac-mini-M4 open-webui % docker compose down

docker compose up -d

[+] Running 3/3

 ✔ Container open-webui        Removed                                                                       1.3s 

 ✔ Container ollama            Removed                                                                       0.1s 

 ✔ Network open-webui_default  Removed                                                                       0.3s 

[+] Running 1/1

 ✔ ollama Pulled                                                                                             1.5s 

[+] Running 3/3

 ✔ Network open-webui_default  Created                                                                       0.1s 

 ✔ Container ollama            Started                                                                       0.2s 

 ✔ Container open-webui        Started                                                                       0.2s 

(base) bhjo0930@Mac-mini-M4 open-webui %

 

3. open webui가 도커로 실행됨으로 호스트로 정보를 바꿔준다. 그리고 필수는 아니지만 응답시 일부 오류가 날 수 있는 상황으로 OLLAMA_STREAM=false 넣는다.

(base) bhjo0930@Mac-mini-M4 open-webui % vi .env

OLLAMA_BASE_URL=http://host.docker.internal:11434

OLLAMA_STREAM=false

 

4. 호출이 정상적으로 동작하는지 테스트

(base) bhjo0930@Mac-mini-M4 open-webui % docker exec -it open-webui curl -X POST http://host.docker.internal:11434/api/generate \

     -H "Content-Type: application/json" \

     -d '{

       "model": "deepseek-r1:latest",

       "prompt": "Hello, how are you?",

       "stream": false

     }'



{"model":"deepseek-r1:latest","created_at":"2025-02-26T14:36:19.516905Z","response":"\u003cthink\u003e\n\n\u003c/think\u003e\n\nHello! I'm just a virtual assistant, so I don't have feelings, but I'm here and ready to help you with whatever you need. How are *you* doing today? 😊","done":true,"done_reason":"stop","context":[151644,9707,11,1246,525,498,30,151645,151648,271,151649,271,9707,0,358,2776,1101,264,4108,17847,11,773,358,1513,944,614,15650,11,714,358,2776,1588,323,5527,311,1492,498,448,8820,498,1184,13,2585,525,353,9330,9,3730,3351,30,26525,232],"total_duration":2932330166,"load_duration":32284500,"prompt_eval_count":9,"prompt_eval_duration":626000000,"eval_count":45,"eval_duration":2271000000}%

 

 

3. Ngjinx 설치

1. 간단히 brew로 설치

(base) bhjo0930@Mac-mini-M4 open-webui % brew install nginx

==> Auto-updating Homebrew...

...

Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that

nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To start nginx now and restart at login:

  brew services start nginx

Or, if you don't want/need a background service you can just run:

  /opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;

==> Summary

🍺  /opt/homebrew/Cellar/nginx/1.27.4: 27 files, 2.5MB

==> Running `brew cleanup nginx`...

Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.

Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

==> Caveats

==> nginx

Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that

nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To start nginx now and restart at login:

  brew services start nginx

Or, if you don't want/need a background service you can just run:

  /opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;

 

2. nginx 시작

(base) bhjo0930@Mac-mini-M4 open-webui % brew services start nginx

==> Tapping homebrew/services

Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-services'...

remote: Enumerating objects: 4105, done.

remote: Counting objects: 100% (543/543), done.

remote: Compressing objects: 100% (210/210), done.

remote: Total 4105 (delta 419), reused 339 (delta 333), pack-reused 3562 (from 2)

Receiving objects: 100% (4105/4105), 1.24 MiB | 24.88 MiB/s, done.

Resolving deltas: 100% (1991/1991), done.

Tapped 2 commands (53 files, 1.5MB).

==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

 

3. 재시작하여 문제 없음 확인

(base) bhjo0930@Mac-mini-M4 open-webui % brew services restart nginx

Stopping `nginx`... (might take a while)

==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)

==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

 

4. https를 위한 인증서 추가

(base) bhjo0930@Mac-mini-M4 certbot % mkdir -p ~/ssl

(base) bhjo0930@Mac-mini-M4 certbot % cd ~/ssl

(base) bhjo0930@Mac-mini-M4 certbot % openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt

-----

Country Name (2 letter code) [AU]:KR

State or Province Name (full name) [Some-State]:Seoul

Locality Name (eg, city) []:Seoul

Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany

Organizational Unit Name (eg, section) []:Dev

Common Name (e.g. server FQDN or YOUR name) []:localhost

Email Address []:bhjo0930@gmail.com

(base) bhjo0930@Mac-mini-M4 ssl % ls ~/ssl

localhost.crt localhost.key

 

5. https, 인증서 및 기타 설정

(base) bhjo0930@Mac-mini-M4 ssl % vi /opt/homebrew/etc/nginx/nginx.conf

...

    server {

        listen       443 ssl;

        server_name  localhost;



        ssl_certificate /Users/bhjo0930/ssl/localhost.crt;

        ssl_certificate_key /Users/bhjo0930/ssl/localhost.key;



        #charset koi8-r;



        #access_log  logs/host.access.log  main;



        location / {

           proxy_pass http://localhost:3000;  # Open WebUI 포트

           proxy_set_header Host $host;

           proxy_set_header X-Real-IP $remote_addr;

           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;



            # WebSocket 지원 추가

            proxy_http_version 1.1;

            proxy_set_header Upgrade $http_upgrade;

            proxy_set_header Connection "Upgrade";



            # JSON 데이터 손실 방지 (버퍼 설정)

            proxy_buffering off;

            proxy_set_header X-Accel-Buffering no;



        }

...

# http로 들어오면 https 로 전달

    server {

        listen 80;

        server_name localhost;

        return 301 https://$host$request_uri;

    }

...

 

6. 설정 테스트

(base) bhjo0930@Mac-mini-M4 ~ % nginx -t                             

nginx: the configuration file /opt/homebrew/etc/nginx/nginx.conf syntax is ok

nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful

 

7. 서비스 재시작

(base) bhjo0930@Mac-mini-M4 open-webui % brew services restart nginx

Stopping `nginx`... (might take a while)

==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)

==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

 

 

첨언, Open Webui 에서 아래와 같이 "SyntaxError: Unexpected token 'd', "data: ("id"... is not valid JSON" 오류가 나면 njinx 설정 확인 하면 된다.

댓글