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

Nginx配置域名转发实例

时间:2015-06-29 19:21:06      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

域名:cps.45wan.com   所在阿里云主机:123.35.9.12

45wan没有在阿里云备案

67wan已经在阿里云备案

阿里云主机(假如123.35.9.12)上原来的nginx配置:

server {
listen 80;
  server_name cps.45wan.com;
  root /home/web/cps.45wan.com/htdocs/www;

  location / {
    root /home/web/cps.45wan.com/htdocs/www;
  }

  location ~ \.php$ {
    root /home/web/cps.45wan.com/htdocs/www;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/web/cps.45wan.com/htdocs/www$fastcgi_script_name;
    include fastcgi_params;
  }
}

由于45wan.com没有在阿里备案,因此cps.45wan.com解析到阿里云主机123.35.9.12后,访问此域名会被阿里拦截

技术分享

为了能快速访问此域名,使用nginx域名转发解决

找一台非阿里云的服务器(假如96.18.150.25)新建一个cps.45wan.com的配置

server {
  server_name cps.45wan.com;
  set $docRoot /home/web/cps.45wan.com;  #此目录为空即可,不需要存在文件
  root $docRoot;
  index index.html;


  location / {
    proxy_pass http://cps.67wan.com ;
  }

}

然后在DNSPOD更改解析cps.45wan.com到96.18.150.25

 

再回到阿里云主机(123.35.9.12)上修改nginx配置

server {
  listen 80;
  # server_name cps.45wan.com;
  server_name cps.67wan.com;
  root /home/web/cps.45wan.com/htdocs/www;

  location / {
  root /home/web/cps.45wan.com/htdocs/www;
  }

  location ~ \.php$ {
    root /home/web/cps.45wan.com/htdocs/www;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /home/web/cps.45wan.com/htdocs/www$fastcgi_script_name;
    include fastcgi_params;
  }
}

 修改完毕reload一下nginx重新访问cps.45wan.com即可正常访问!

技术分享

Nginx配置域名转发实例

标签:

原文地址:http://www.cnblogs.com/fjping0606/p/4607871.html

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