zwalts
zwalts

Reputation: 3

Nginx Reverse Proxy Multiple Applications on One Domain

like these:

 test1.sec.com  192.168.1.8:8001<br>
 test2.sec.com  192.168.1.8:8002<br>
 test3.sec.com  192.168.1.8:8003<br>

 http://www.sec.com/test1/   192.168.1.8:8001<br>
 http://www.sec.com/test2/   192.168.1.8:8002<br>  
 http://www.sec.com/test3/   192.168.1.8:8003<br>

how to config the nginx.conf ?

Upvotes: 0

Views: 1843

Answers (1)

Keenan Lawrence
Keenan Lawrence

Reputation: 1464

You haven't provided much information, but based on what you gave, this should work:

server {
    listen 80;
    server_name test1.sec.com;

    location / {
        proxy_pass http://192.168.1.8:8001;
    }
}

server {
    listen 80;
    server_name test2.sec.com;

    location / {
        proxy_pass http://192.168.1.8:8002;
    }
}

server {
    listen 80;
    server_name test3.sec.com;

    location / {
        proxy_pass http://192.168.1.8:8003;
    }
}

Then, for your www.sec.com, you'll need to add separate location blocks to catch the /test/ URIs.

server {
    listen 80;
    server_name www.sec.com;

    location /test1/ {
        redirect 301 $scheme://test1.sec.com;
    }

    location /test2/ {
        redirect 301 $scheme://test2.sec.com;
    }

    location /test3/ {
        redirect 301 $scheme://test3.sec.com;
    }

    #Rest of your config here...
}

Note: You have to specify your test location blocks before your root (/) unless you use a modifier to give them precedence.

Upvotes: 2

Related Questions