简体   繁体   中英

Want to redirect old domain to new domain using nginx but not working

I have set the two Sub domain for front end and back end code. I want to redirect the new domain name if user hit the old domain. But I am getting error- "414 Request-URI Too Large". I am using Nginx server for back end code.

 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;
    }
  }

you can redirect using this:

server {
                 listen 80;
                 server_name dev.domain1.com;
                 rewrite ^/(.*) https://dev.domain2.com/$1 permanent;
        }

Try this

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

您可以尝试像这样的重定向。

 return           301 http://dev.newdomain.com$request_uri;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM