简体   繁体   English

如何配置nginx将所有未处理的域转发到特定服务?

[英]How to configure nginx to forward all unhandled domains to particular service?

I don't think it's anywhere here as I was looking for that a while, but forgive me if you find my question possible duplicate. 我想找一会儿也没在这里,但是如果您发现我的问题可能重复,请原谅。

I have VPS server. 我有VPS服务器。 All websites there run in docker containers with nginx / nginx-gen / nginx lets encrypt companion in the front. 那里的所有网站都在docker容器中运行,并带有nginx / nginx-gen / nginx,可以在前面加密伴侣。

I have one largest app there which will enable users to add their domains to point this app. 我在那里有一个最大的应用程序,它将使用户能够添加他们的域来指向该应用程序。 I have to have it automated. 我必须将其自动化。 My app will handle domains accordingly and that's not an issue. 我的应用程序将相应地处理域,这不是问题。

The question is how to set up nginx to forward all requests for domains which are not handled by any other containers (so they are getting separate config blocks) to my app which is one of the containers. 问题是如何设置nginx来转发对所有其他容器未处理的域的请求(因此它们将获得单独的配置块)转发到我的应用(容器之一)。

Is there any way to do that? 有什么办法吗?

It's very simple to do: 这很简单:

docker-compose.yml docker-compose.yml

version: '2'
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx.tmpl:/app/nginx.tmpl
    environment:
      - DEFAULT_HOST=whoami2.local

  whoami:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami.local

  whoami2:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami2.local

In this way everything that is not defined as domain within nginx will be redirected to whoami2 service. 这样,所有未在nginx中定义为域的内容都将被重定向到whoami2服务。

I hope this change works for you 我希望这个改变对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM