码迷,mamicode.com
首页 > 其他好文 > 详细

nginx配置之tomcat支持多域名

时间:2015-01-05 23:21:18      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

nginx.conf

 

user  www www;
worker_processes  1;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
events {
    use epoll;
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;
 
    sendfile        on;
    #tcp_nopush     on;
 
    keepalive_timeout  65;
    include gzip.conf;
 
    server {
        listen       80;
        server_name  localhost;
 
        location / {
            deny all;
        }
 
        location ~ ^/NginxStatus {
            stub_status on;
            access_log off;
            allow   127.0.0.1;
            allow   42.96.200.198;
            deny    all;
        }
 
    }
 
    server {
        listen 80;
        server_name www.tojsp.com;
 
        access_log  logs/tojsp.log;
 
    location ~ ^/NginxStatus {
            stub_status on;
            access_log off;
        }
 
    location ~ ^/(WEB-INF)/ {
            deny all;
        }
 
        location ~ \.(gif|jpg|jpeg|png)$ {
            root /xdata/www/resource/tojsp;
        access_log off;
            expires 24h;
        }
 
        location / {
            proxy_pass http://localhost:8080;
            include proxy.conf;
        }
    }
 
    server {
        listen 80;
        server_name it.tojsp.com;
 
        access_log  logs/tojsp.log;
 
    location ~ ^/NginxStatus {
            stub_status on;
            access_log off;
        }
 
    location ~ ^/(WEB-INF)/ {
            deny all;
        }
 
        location ~ \.(gif|jpg|jpeg|png)$ {
            root /xdata/www/resource/tojsp;
        access_log off;
            expires 24h;
        }
 
        location / {
            proxy_pass http://localhost:8080;
            include proxy.conf;
        }
    }
}

2. 再配置tomcat中的server.xml, 找到Host节点

server.xml

<Host name="www.tojsp.com"  appBase="/xdata/www/tojsp.com"
    unpackWARs="true" autoDeploy="true">
 
    <Context path="" docBase="/xdata/www/tojsp.com" reloadable="true" />
</Host>
<Host name="it.tojsp.com"  appBase="/xdata/www/it.tojsp.com"
    unpackWARs="true" autoDeploy="true">
 
    <Context path="" docBase="/xdata/www/it.tojsp.com" reloadable="true" /> 
</Host>
 

3.最后启动nginx与tomcat看看效果,是不是成功了。

nginx配置之tomcat支持多域名

标签:

原文地址:http://www.cnblogs.com/xzjie/p/4204747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!