简体   繁体   English

虚拟主机上的nginx子域配置

[英]nginx subdomain configuration on virtual host

There are several questions on SO about nginx subdomain configuration but didn't find one that exactly the same as mine. 有关nginx子域配置的SO有几个问题,但没有找到与我的完全相同的问题。

Say I got a virtual host some.example.com from higher-level net admin example.com at our organization. 假设我从我们组织的更高级别的net admin example.com获得了一个虚拟主机some.example.com I want to use some.example.com as my primary site and use foo.some.example.com and bar.some.example.com for auxiliary usage (proxy, etc). 我想使用some.example.com作为我的主站点,并使用foo.some.example.combar.some.example.com进行辅助使用(代理等)。 I tried this simple configuration and put it under sites-enabled but didn't work: 我尝试了这个简单的配置并将其置于sites-enabled但未运行的情况下:

server {
    listen 80; 
    server_name some.example.com;
    root /home/me/public_html/some;
    index index.html index.htm;
}

server {
    listen 80; 
    server_name foo.some.example.com;
    root /home/me/public_html/foo;
    index index.html index.htm;
}

server {
    listen 80; 
    server_name bar.some.example.com;
    root /home/me/public_html/bar;
    index index.html index.htm;
}

In this setting some.example.com works fine, but for the other two browser return that could not find foo.some.example.com . 在此设置中, some.example.com工作正常,但对于另外两个could not find foo.some.example.com浏览器返回。 I'm running it on a ubuntu server. 我在ubuntu服务器上运行它。

Is there something wrong with this configuration? 这个配置有问题吗? Or is it something I should talk to higher level net admin (make foo.some.example.com and bar.some.example.com to be registered)? 或者我应该与更高级别的网络管理员交谈(使foo.some.example.combar.some.example.com注册)?

Sub-domain configuration starts with an entry in the DNS server of the parent domain and the lookup resolves the sub-domain to an IP address of the web server. 子域配置以父域的DNS服务器中的条目开始,并且查找将子域解析为Web服务器的IP地址。 The web server in turn delegates the requests based on its configuration for the sub-domain. Web服务器依次根据子域的配置委托请求。

If you don't have a DNS setup in your sub-domain, then the admin at example.com needs to set up a CNAME alias. 如果您的子域中没有DNS设置,则example.com上的admin需要设置CNAME别名。 The alias points the subdomain to the same web server, which hosts the website for the parent domain. 别名将子域指向同一个Web服务器,该服务器承载父域的网站。 The canonical names (CNAMES) are added for each of the subdomains. 为每个子域添加规范名称(CNAMES)。 Once the subdomain is resolved to the IP address of the web server, the web server can route the request to a different website. 一旦子域解析为Web服务器的IP地址,Web服务器就可以将请求路由到其他网站。

CNAME is just a way to get the web traffic to your IP address. CNAME只是一种将网络流量传输到您的IP地址的方法。 The request will still include the original name in the Host: header. 该请求仍将在Host:标头中包含原始名称。

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

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