域名: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配置域名转发实例-LMLPHP

为了能快速访问此域名,使用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配置域名转发实例-LMLPHP
04-30 20:33