Nginx到服务器的路由路径 [英] Nginx Routing path to server

查看:199
本文介绍了Nginx到服务器的路由路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个站点.每个站点都有其自己的服务器"部分,其server_name如下所示

I have a few sites. Each site has its own "server" section with a server_name that looks like this

server {
   ...
   server_name siteA.example.com;
   root /var/www/siteA;
   ...
}

因此,我可以使用 http://siteA.example.com

不过,我还需要使用url http://example.com/siteA 来打开网站. 该怎么办?

I however also need to bring up the site by using the url http://example.com/siteA How can this be done?

推荐答案

要在下面的配置中添加两个选项...

Two options to add to your config below ...

选项1:

server {
    ...
    server_name example.com;
    ...
    location /siteA {
        root /var/www/siteA;
        ...
    }
    location /siteB {
        root /var/www/siteB;
        ...
    }
    ...
}

选项2:

server {
    ...
    server_name example.com;
    ...
    location /siteA {
        return       301 http://siteA.example.com$request_uri;
    }
    location /siteB {
        return       301 http://siteB.example.com$request_uri;
    }
    ...
}

第一个选项仅从example.com/siteA提供服务,而第二个选项重定向到siteA.example.com

First option simply serves from example.com/siteA in addition while second option redirects to siteA.example.com

这篇关于Nginx到服务器的路由路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆