Nginx 多域到一台服务器配置

发布于 2025-01-10 18:34:57 字数 2262 浏览 0 评论 0原文

我的服务器中有 1 个应用程序。
www.mainsite.com/adminindex
www.mainsite.com/landingpage

我希望多个域能够打开此应用程序并且仍然使用 Nginx 屏蔽/代理域 URL。但无论我做了什么配置,它只是重定向,如何设置配置?

假设这是多个域 ->
www.domainsite1.com/adminindex
www.domainsite1/landingpage

www.domainsite2.com/adminindex
www.domainsite2/landingpage

所以当我打开时

www.domainsite1.com/adminindex

,它将打开

www.mainsite.com/adminindex

但 URL 保持不变

www.domainsite1.com/adminindex

我已经将domainsite1 A记录设置为Nginx IP。 这是我当前的 Nginx 配置:

server {
  listen 80 default_server;
  #listen 443 ssl;
  server_name www.domainsite1.com/;

   location / {
     #  proxy_set_header        Host $host;
     #  proxy_set_header        X-Real-IP $remote_addr;
     #  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
     #  proxy_set_header        X-Forwarded-Proto $scheme;

     proxy_set_header X-Real-IP $remote_addr;
     proxy_pass   https://www.mainsite.com/index;
     # Add the trailing slash
     # rewrite ^([^.]*[^/])$ $1/ permanent;
    }
}

server {
  listen 80 default_server;
  #listen 443 ssl;
  server_name www.domainsite2.com/;

  location / {
    #  proxy_set_header        Host $host;
    #  proxy_set_header        X-Real-IP $remote_addr;
    #  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    #  proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass   https://www.mainsite.com/index;
    # Add the trailing slash
    # rewrite ^([^.]*[^/])$ $1/ permanent;
    }
 }

谢谢。

I have 1 app in a server.
www.mainsite.com/adminindex
www.mainsite.com/landingpage

And I would like multiple domains to be able to open this app and still mask/proxy the domain URL using Nginx. But whichever configuration I did, it just redirect, how do set the configuration ?

Let say this is the multiple domains ->
www.domainsite1.com/adminindex
www.domainsite1/landingpage

www.domainsite2.com/adminindex
www.domainsite2/landingpage

So when I open

www.domainsite1.com/adminindex

, it will open the

www.mainsite.com/adminindex

but the URL stays the same

www.domainsite1.com/adminindex

.

I have already set domainsite1 A record to the Nginx IP.
This is my current Nginx configuration :

server {
  listen 80 default_server;
  #listen 443 ssl;
  server_name www.domainsite1.com/;

   location / {
     #  proxy_set_header        Host $host;
     #  proxy_set_header        X-Real-IP $remote_addr;
     #  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
     #  proxy_set_header        X-Forwarded-Proto $scheme;

     proxy_set_header X-Real-IP $remote_addr;
     proxy_pass   https://www.mainsite.com/index;
     # Add the trailing slash
     # rewrite ^([^.]*[^/])$ $1/ permanent;
    }
}

server {
  listen 80 default_server;
  #listen 443 ssl;
  server_name www.domainsite2.com/;

  location / {
    #  proxy_set_header        Host $host;
    #  proxy_set_header        X-Real-IP $remote_addr;
    #  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    #  proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass   https://www.mainsite.com/index;
    # Add the trailing slash
    # rewrite ^([^.]*[^/])$ $1/ permanent;
    }
 }

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖个坑埋了你 2025-01-17 18:34:57

如果只是您的域名不同,并且您想将其解析为多个地址而不更改 uri,则可以使用此功能,只需将域名保留在 proxy_pass 中即可>/

无论域名是什么,最终都会解析为 -

  • www.example.com/xxxx/ -> /xxxx/ -> https://www.mainsite.com/xxxx
  • www.exampletwo.com/yyyy/ -> /yyyy/ -> https://www.mainsite.com/yyyy
  • ww.examplethird.com,-> <代码>/ -> https://www.mainsite.com/
/ {
    .
    .
    proxy_pass   https://www.mainsite.com/;
    }

如果您想了解更多信息 - 链接

If only your domain name is different and you would like to resolve it to several address with no changes in uri, You can use this just keep domain name in proxy_pass with /

No matter what is the domain name, it will eventualy resolve to -

  • www.example.com/xxxx/ -> /xxxx/ -> https://www.mainsite.com/xxxx
  • www.exampletwo.com/yyyy/ -> /yyyy/ -> https://www.mainsite.com/yyyy
  • ww.examplethree.com, -> / -> https://www.mainsite.com/
/ {
    .
    .
    proxy_pass   https://www.mainsite.com/;
    }

If you would like to know more info - Link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文