简体   繁体   English

想要使用Nginx将旧域重定向到新域,但不起作用

[英]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. 我已经为前端和后端代码设置了两个Sub域。 I want to redirect the new domain name if user hit the old domain. 如果用户点击旧域名,我想重定向新域名。 But I am getting error- "414 Request-URI Too Large". 但是我收到错误消息-“ 414请求URI太大”。 I am using Nginx server for back end code. 我正在使用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;
    }
  }

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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