Nginx配置域名转发实例

域名: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即可正常访问!

时间: 2024-10-10 06:04:08

Nginx配置域名转发实例的相关文章

nginx 配置域名转发

自己测试环境,配置下载目录和一个jenkins的地址: 域名跳转,反向代理 # cat ../nginx.conf user www www; worker_processes 1; error_log logs/error.log info; pid logs/nginx.pid; worker_rlimit_nofile 65535; events { worker_connections 65535; use epoll; } http { include mime.types; defa

nginx做域名转发和uri转发

一. 域名转发 www.qq.com ------> www.baidu.com nginx部署在192.168.1.100,本地配置host 192.168.1.100 www.qq.com ,浏览器输入www.qq.com会跳转到www.baidu.com # vi  /etc/nginx/nginx.conf user nginx;worker_processes 1; events { use epoll; worker_connections 10240; } http { serve

nginx 多域名转发

nginx配置多域名转发其实蛮简单的,网上都是资料. 我纠结的是我配置成功的第二个域名,转发不添加项目名 就找不到我的项目. 一直在想是不是nginx配置出了问题,后来转念一想. 是因为我的项目在tomcat中没有放在ROOT目录下.

nginx配置域名跳转

nginx 配置主域名 xxx.com, 跳转子域名 www.xxx.com server {listen 80;server_name www.xxx.com; location / { root html/www/public_html; index index.php index.html index.htm; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { r

Linux JDK Tomcat Nginx MariaDB 安装,Nginx 多域名转发配置

安装JDK rpm包下载地址(jdk-7u17 ): http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u17-oth-JPR # yum install wget -y JDK下载地址: http://download.oracle.com/otn/java/jdk/7u17-b02/jdk-7u17-linux-x64.rpm?Auth

Nginx配置域名跳转实例

要求:浏览器地址栏输入qj.123.com之后,地址自动变成qj.abc.com 配置nginx跳转 server { listen 80; server_name qj.abc.com qj.123.com; set $domain qj.abc.com; index index.php index.html index.htm; root /home/web/$domain/htdocs/; if ( $host = 'qj.123.com' ){ rewrite ^/(.*)$ http:

Nginx配置请求转发location及rewrite规则

一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # 因为所有的地址都以 / 开头,所以这条规则将匹配到所有请求 # 但是正则和最长字符串会优先匹配 [ configuration B ] } location /documents/ { # 匹配任何以 /documents/ 开头的地址,匹配符合以后,还要继续往下搜索 # 只有后面的正则表达式没有匹配到时,这一条才会采用这一条 [ c

nginx配置salt-api转发

配置nginx对salt-api的https转发,以下是nginx配置文件 upstream saltapi.local { server 192.186.156.55:8090 weight=10 max_fails=2 fail_timeout=30s; } server { listen 443 default ssl; server_name 192.186.156.55; access_log /export/servers/nginx/logs/saltapi.local/salta

Nginx配置proxy_pass转发的/路径问题

在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走. location ^~ /static_js/ { proxy_cache js_cache; proxy_set_header Host js.test.com; proxy_pass http://js.test.com/; } 如上面的配置,如