简体   繁体   English

配置Nginx仅为一个端点服务

[英]Configure Nginx to serve one endpoint only

I am using Flask. 我正在使用Flask。

I have my site configured in nginx at www.example.com/. 我在www.example.com/上的nginx中配置了我的网站。

Now my requirement is to serve one of the endpoint in my app using different domain say www.example2.com . 现在我的要求是使用不同的域名www.example2.com为我的应用程序中的一个端点提供服务。

so it can be accessed www.example2.com/custom 所以可以访问www.example2.com/custom

Note that I want to use www.example2.com domain name only for this endpoint. 请注意,我只想为此端点使用www.example2.com域名。 Is this possible in Nginx? 这可能在Nginx中吗?

Here is my Nginx configuration for reference. 这是我的Nginx配置供参考。

# the upstream component nginx needs to connect to
upstream flask {
    server unix:///home/ubuntu/opt/app/mobifly.sock fail_timeout=0; # for a file socket
}

# configuration of the server
server {
    server_name www.example.com www.example2.com;
    listen         80;

    client_max_body_size 2000M;
    proxy_read_timeout 6000;

    location / {
        include     uwsgi_params;
        uwsgi_pass  unix:/home/project/path/to/project.sock;
    }

}

Currently I can access all the urls using both the domains but I want to configure as I specified above. 目前我可以使用这两个域访问所有网址,但我想按照上面的指定进行配置。

Create another server block exclusively for that server_name with a single location that matches /custom only. 仅为该server_name创建另一个服务器块 ,其中一个location仅匹配/custom

server {
    server_name www.example.com
    ...
    location / {
        ...
    }
}


server {
    server_name www.example2.com
    ...
    location /custom {
        ...
    }
}

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

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