Nginx将一个域重定向到另一个域内的子文件夹

Nginx将一个域重定向到另一个域内的子文件夹

product.comcompany.com

我很想弄清楚如何告诉 DNS 和 Nginx 重定向product.com到域内的文件夹company.com

理想情况下,所有这些排列

http://product.com
https://product.com
http://www.product.com
https://www.product.com

将用户重定向到company.comat内的子文件夹

https://company.com/product

哦还有

这是我当前的 Nginx 配置company.com

server {
  listen 443 ssl;
  server_name company.com www.company.com;

  if ($host = 'www.company.com') {
    return 301 https://company.com$request_uri;
  }

  root /var/www/company.com/html;
  index index.php index.html index.htm;

  include /etc/nginx/compression.conf;
  include /etc/nginx/php.conf;
  include /etc/nginx/assets.conf;
  include /etc/nginx/restrictions.conf;

  ssl_certificate /etc/letsencrypt/live/company.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/company.com/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

server {
  listen 80;
  server_name company.com www.company.com;
  return 301 https://company.com$request_uri;
}

请告诉我

1)product.com 和 compnay.com 需要哪些 DNS 记录

2)对于 product.com 和 compnay.com,我需要哪些 Nginx 规则

谢谢你!

答案1

在 nginx 中,我认为重写可以做到这一点。例如:

rewrite ^/product(.*) https://$host/company.com/product$1 permanent;

相关内容