基於 Docker 的 NginX,適用於一個應用程式和多個網域

基於 Docker 的 NginX,適用於一個應用程式和多個網域

我使用 docker 和 nginx 映像來運行我的網站。

我有以下配置:

docker-compose.yml

version: '7.1'

services:
  #
  # Conflicts with any local HTTP server.
  # If you have a local Nginx, you must stop it.
  #
  nginx:
    image: nginx:1.12.0-alpine
    container_name: nginx
    ports:
      - "80:80"
    volumes:
      - ./files/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./files/nginx/sites-enabled:/etc/nginx/sites-enabled:ro
    network_mode: bridge

站點一.conf

upstream site-one.local {
  server host.docker.internal:9293 fail_timeout=0;
}

server {
  listen 80;
  server_name site-one.local *.site-one.local;

  client_max_body_size 50M;
  error_page 500 502 503 504 /50x.html;

  location = /50x.html {
    root html;
  }

  try_files $uri/index.html $uri @site-one.local;
  location @site-one.local {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://site-one.local;
  }
}

我在 Web 應用程式中有選項卡,當單擊時,會使用新網域開啟頁面site-two.local/my-page並返回錯誤:

該網站不能是 site-two.local 拒絕連線。

site-two.local如何為相同應用程式新增額外的網域?

答案1

如何為相同應用程式新增額外的網域 site-two.local?

更改server_name配置應該可以...但我不確定這個錯誤是由 nginx 還是您的應用程式引起的。

  server_name site-one.local *.site-one.local site-two.local *.site-two.local;

server {...也許為 site-two.local創建另一個區塊也可以。

相關內容