# docker架設n8n跟nginx proxy 架設n8n時,因為要使用url name來進行連結,但是沒有哪麼多網址時,只能用nginx設定path方式。將proxy導至docker的n8n服務,具體實現的作法如下: ## docker compose 建立docker-compose.yml ```yaml! version: '3.8' volumes: db_storage: n8n_storage: services: postgres: image: postgres:16 restart: always environment: - POSTGRES_USER - POSTGRES_PASSWORD - POSTGRES_DB - POSTGRES_NON_ROOT_USER - POSTGRES_NON_ROOT_PASSWORD volumes: - db_storage:/var/lib/postgresql/data - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh healthcheck: test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}'] interval: 5s timeout: 5s retries: 10 n8n: image: docker.n8n.io/n8nio/n8n restart: always environment: - DB_TYPE=postgresdb - DB_POSTGRESDB_HOST=postgres - DB_POSTGRESDB_PORT=5432 - DB_POSTGRESDB_DATABASE=${POSTGRES_DB} - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER} - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD} - N8N_HOST=${DOMAIN_NAME} - N8N_PATH=/n8n/ #此為設定path - WEBHOOK_URL=http://localhost:5678/n8n/ - TZ=Asia/Taipei ports: - "5678:5678" links: - postgres volumes: - ./n8n_storage:/home/node/.n8n depends_on: postgres: condition: service_healthy ``` 建立.env,,此為設定資料庫連線資訊 ```bash! POSTGRES_USER=isUser POSTGRES_PASSWORD=isUserPASSWORD POSTGRES_DB=n8n POSTGRES_NON_ROOT_USER=isDbUser POSTGRES_NON_ROOT_PASSWORD=isDbUserPASSWORD DOMAIN_NAME=localhost ``` 設定好後執行docker ```bash! docker-compose up -d ``` 跑起來後檢視docker是否運作正常  因為n8n有設定path,要藉由nginx的proxy子目錄才能進行測試 ## nginx設定 nginx設定location path為/n8n/並導向至port 5678 ```bash! location /n8n/ { # 允许跨域请求 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_cache_bypass $http_upgrade; proxy_pass http://localhost:5678/; } ``` 然後重啓nginx後,即可用url方式連至/n8n/看看運作是否正常。 連結為:https://youUrl/n8n/  >參考連結: >https://linux.do/t/topic/474096 >https://dstipscafe.github.io/blogs/p/self_host_n8n/ > ###### tags:`docker`,`n8n`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up