Nginx Routing path to server

后端 未结 1 2010
故里飘歌
故里飘歌 2020-12-14 05:21

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;
   ro         


        
相关标签:
1条回答
  • 2020-12-14 05:49

    Two options to add to your config below ...

    Option 1:

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

    Option 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;
        }
        ...
    }
    

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

    0 讨论(0)
提交回复
热议问题