`

多域名配置在一个IP

 
阅读更多
一、配置tomcat

1、安装tomcat
copy tomcat server 至
/prod/xxx/tomcat-6.0.41-1/

2、修改tomcat用户

<role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="admin"/>
  <role rolename="manager-gui"/>
  <user username="zhangs" password="zhangs123" roles="tomcat,admin,manager-gui"/>

3、配置server.xml

8080默认端口
<Server port="36421" shutdown="SHUTDOWN">

<Connector port="37658" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="35846" />

<Connector port="34872" protocol="AJP/1.3" redirectPort="35846" />

更改tomcat默认根目录


<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
	[b]<Context path="" docBase="myproject" debug="0" reloadable="true" />[/b]
      </Host>



在\conf\Catalina目录下建立,然后建立ROOT.xml文件,其格式和\conf\localhost目录下的ROOT.xml一致,但是内容如下:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="Welcome to my project!" docBase="/pord/xxx/webapp/myproject" path="">
</Context>


reference:http://www.cnblogs.com/wenanry/archive/2012/04/16/2451802.html


注释:
对上面语句做下解释:该句是设置Tomcat的虚拟路径,书写语法是<Context path="虚拟目录" docBase="实际目录(可以是相对路径如上)" debug="0" reloadable="true" crossContext="true" />,我将网站实际根目录映射到了F:/MyWeb,于是更改了网站跟目录的映射。
这种修改方式的结果是:localhost依然是最初的webapps,但网站的根目录是F:/MyWeb,相当于把原始的ROOT目录映射成F:/MyWeb,以后写的网站直接放到F:/MyWeb下,运行http://localhost:8080/index.jsp,就能访问了。而且,由于localhost的路径没变,所以Tomcat Manager可以继续使用。可以把原先ROOT中的文件都复制到MyWeb下做下测试。



二、nginx 配置 现在要配置两个域名:www.abc1.com 与 www.abc2.com

1、安装nginx

2、配置nginx confi

/etc/nginx/conf.d

更改default.conf为abc1.conf 且内容为:
server {
    listen       80;
   #server_name  localhost;

    server_name www.abc1.com ;
    #if ($host = 'abc1.com' ) {
    #   rewrite ^/(.*)$ http://www.abc1.com/$1 permanent;
    #}

   # rewrite ^/(.*) http://www.abc1.com/$1 permanent;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /prod/www/abc1;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
 error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

 # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}



新建文件abc2.conf ,内容如下:

upstream mytomcats {
      server localhost:37658;
      #ip_hash;
}

server {
    listen       80;

    server_name www.abc2.cn ;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
          proxy_pass http://mytomcats;
          proxy_redirect off;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          client_max_body_size 10m;
          client_body_buffer_size 128k;
          proxy_connect_timeout 90;
          proxy_send_timeout 90;
          proxy_read_timeout 90;
          proxy_buffer_size 4k;
          proxy_buffers 4 32k;
          proxy_busy_buffers_size 64k;
          proxy_temp_file_write_size 64k;
     }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}

}



3、重启nginx

/etc/init.d/nginx restart




referenece:
http://blog.itpub.net/14184018/viewspace-749955/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics