Nginx反向代理在一个域上的多个应用程序

时间:2016-08-23 07:53:09

标签: nginx

喜欢这些:

function get_all_notification() { //get all notification based on the 'notification' table left join by 'membership' table

    $this->db->select('*')->from('notification')->join('membership','membership.membership_id = notification.notif_id','left');
    $notif = $this->db->get();
    return $notif->result();
}

如何配置nginx.conf?

1 个答案:

答案 0 :(得分:0)

您没有提供太多信息,但根据您提供的信息,这应该有效:

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

然后,对于www.sec.com,您需要添加单独的位置块来捕获/test/ URI。

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

注意:您必须在根(test)之前指定/位置块,除非您使用修饰符赋予它们优先权。