简体   繁体   English

如何配置子域以使用Nginx在主域上打开子页面?

[英]How to configure a subdomain to open a subpage on the main domain with nginx?

So I have a domain example.com and a subdomain sub.example.com. 所以我有一个域example.com和一个子域sub.example.com。

I would like to configure my Nginx virtual host to open the root site when a user uses the domain example.com but when a user uses sub.example.com the server should serve example.com/sub. 我想将Nginx虚拟主机配置为在用户使用域example.com时打开根站点,但是当用户使用sub.example.com时,服务器应为example.com/sub服务。 The main problem I'm having is the URL changing. 我遇到的主要问题是URL更改。 I do not want to simply redirect, instead, the URL should stay the same. 我不想简单地重定向,相反,URL应该保持不变。

So basically you can open the same page by visiting example.com/sub or sub.example.com but the URL should always be sub.example.com. 因此,基本上,您可以通过访问example.com/sub或sub.example.com来打开同一页面,但URL始终应为sub.example.com。

In your nginx configuration file for sub.example.com , under location / , You can proxy-pass to the page you want to show. sub.example.com nginx配置文件中的location /下,您可以proxy-pass到要显示的页面。 In this case example.com/sub . 在这种情况下为example.com/sub But if you have more links on example.com/sub page, your routing would need some tweaks. 但是,如果您在example.com/sub页面上有更多链接,则路由需要进行一些调整。 Else, it should work fine. 否则,它应该可以正常工作。

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

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