文章标题

ngnix 根据不同域名转发不同服务
场景:
我只有一台阿里云服务器,然后搭建了两个网站A,B
有两个域名:www.yunmasoft.com ,www.yhskyc.com
目的:
(1)访问两个域名时都是访问同一台主机
(2)www.yunmasoft.com 访问网站A;
www.yhskyc.com访问的是网站B
使用nginx 如何实现呢?
期望:
http://www.yunmasoft.com/ 访问 tomcat:/home/whuang/software/apache/apache-tomcat-7.0.53
http://www.yhskyc.com/ 访问 tomcat:/home/whuang/software/apache/tomcat-7.0.53_yh
两个域名访问的是不同的tomcat 服务
nginx配置步骤:
步骤一:安装nginx
请自行谷歌

步骤二:创建映射文件
创建目录:/usr/local/nginx-1.7.8/vhosts
在/usr/local/nginx-1.7.8/vhosts 中创建两个文件:
yhskyc.com.conf yunmasoft.com.conf
yhskyc.com.conf 内容为:

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

        location / {
                proxy_pass    http://182.92.97.72:8084;
        #       proxy_redirect off ;

                index index.php index.html index.htm;
        }
        error_page 500 502 503 504 /50x.html;


}

yunmasoft.com.conf 内容如下:

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

        location / {
                proxy_pass    http://182.92.97.72:8083;
                # proxy_redirect on ;

                index index.php index.html index.htm;
        }
        error_page 500 502 503 504 /50x.html;


}

步骤三:把这两个文件包含到nginx主配置文件
修改/conf/nginx.conf
在html节点添加
include /usr/local/nginx-1.7.8/vhosts/*;

/conf/nginx.conf 内容如下:

#user  nobody;
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 {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        add_header Access-Control-Allow-Origin *;
            root   /var/www/html;
            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   html;
        }
  }
include /usr/local/nginx-1.7.8/vhosts/*;
}

参考:http://blog.csdn.net/zacklin/article/details/7859680

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值