简体   繁体   English

如何将 Nginx 配置为反向代理来执行 this.network 模式?

[英]How to configure Nginx as reverse proxy to do this network schema?

I have two Docker instances running Wordpress and my Nodejs application separately in the same machine.我有两个 Docker 实例分别在同一台机器上运行 Wordpress 和我的 Nodejs 应用程序。

Now I want to set up Nginx to accept connections only on my domain (mydomain.com).现在我想设置 Nginx 以仅接受我的域 (mydomain.com) 上的连接。 So if users access to mydomain.com/ they should be redirected to wordpress container, and if they access to mydomain.com/customer, the request should be redirected to Nodejs app container.因此,如果用户访问 mydomain.com/,他们应该被重定向到 wordpress 容器,如果他们访问 mydomain.com/customer,请求应该被重定向到 Nodejs 应用程序容器。

This schema explains the idea:这个模式解释了这个想法:

网络模式

I am not very good at Nginx and it is being so difficult for me to edit the config.我不太擅长 Nginx,而且我很难编辑配置。 file to match that schema.文件以匹配该模式。 Also I dont find any kind of examples or documentation to achieve this configuration.此外,我没有找到任何类型的示例或文档来实现此配置。 Is it so weird?有这么奇怪吗?

It is the very common nginx usage example.这是非常常见的 nginx 用法示例。 The very basic setup you need is您需要的最基本设置是

server {
    listen 80;
    server_name mydomain.com;
    proxy_set-header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    location / {
        proxy_pass http://<docker1_address:port>;
    }
    location /customer {
        proxy_pass http://<docker2_address:port>;
    }
}
server {
    # this would be the default server for all requests
    # where HTTP Host header is missing or not equal to 'mydomain.com'
    listen 80 default_server;
    # close the connection immediately
    return 444;
}

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

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