Nginx+Tomcat实现单IP、多域名、多站点的访问

Nginx配置例子

域名A:www.a.com的配置文件如下:

server {
    listen       80;
    server_name  *.a.com;
    location / {
        proxy_pass http://localhost:8080/projectA/;
        proxy_set_header   Host    $host;
        proxy_set_header   X-Real-IP   $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

域名B:www.b.com的配置文件如下:

server {
    listen       80;
    server_name  *.b.com;
    location / {
        proxy_pass http://localhost:8080/projectB/;
        proxy_set_header   Host    $host;
        proxy_set_header   X-Real-IP   $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

发表评论

邮箱地址不会被公开。