想要使用nginx将旧域重定向到新域但不能正常工作

时间:2018-02-27 08:55:07

标签: php nginx

我为前端和后端代码设置了两个Sub域。如果用户点击旧域,我想重定向新域名。但我收到错误 - " 414 Request-URI Too Large"。我正在使用Nginx服务器作为后端代码。

 server {
    root /var/www/html/frontendCode/dist;
    index index.php index.html index.htm;
    server_name dev.olddomain.com;
    location / {
            try_files $uri $uri/ /index.html;
     }
   rewrite  ^ $scheme://dev.newdomain.com$request_uri permanent;
 }

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name devapi.olddomain.com;
    root /var/www/html/apiBackendCode/public;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;
    rewrite  ^ $scheme://devapi.newdomain.com$request_uri permanent;
     location / {

            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.php?$args;

    }

    location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            try_files $uri =404;
    }
  }

1 个答案:

答案 0 :(得分:1)

试试这个

  server {
      server_name .mydomain.com;
      rewrite ^ http://www.adifferentdomain.com$request_uri? permanent;
    }