2016-03-09 87 views
6

例如,我有一个域名为example.com的网站。在那个网站上,我有一个像这样的页面example.com/hello。现在我需要将我的第二个域名hello.com指向该页面example.com/hello。它不应该是一个重新指导。访客应留在hello.com,但看到页面example.com/hello的内容。这可能吗?我们可以在DNS或Nginx中做到吗?如何将域名指向另一个网站的页面?

使用代理通液之后的访问日志:

123.231.120.120 - - [10/Mar/2016:19:53:18 +0530] "GET/HTTP/1.1" 200 1598 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" 
123.231.120.120 - - [10/Mar/2016:19:53:18 +0530] "GET /a4e1020a9f19bd46f895c136e8e9ecb839666e7b.js?meteor_js_resource=true HTTP/1.1" 404 44 "http://swimamerica.lk/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.$ 
123.231.120.120 - - [10/Mar/2016:19:53:18 +0530] "GET /9b342ac50483cb063b76a0b64df1e2d913a82675.css?meteor_css_resource=true HTTP/1.1" 200 73 "http://swimamerica.lk/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.262$ 
123.231.120.120 - - [10/Mar/2016:19:53:18 +0530] "GET /images/favicons/favicon-16x16.png HTTP/1.1" 200 1556 "http://swimamerica.lk/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" 
123.231.120.120 - - [10/Mar/2016:19:53:19 +0530] "GET /images/favicons/favicon-96x96.png HTTP/1.1" 200 1556 "http://swimamerica.lk/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" 
123.231.120.120 - - [10/Mar/2016:19:53:19 +0530] "GET /images/favicons/favicon-32x32.png HTTP/1.1" 200 1556 "http://swimamerica.lk/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" 
123.231.120.120 - - [10/Mar/2016:19:53:19 +0530] "GET /images/favicons/android-icon-192x192.png HTTP/1.1" 200 1556 "http://swimamerica.lk/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" 
+0

如果'hello'是DIR你为什么不设置该域的服务器? –

+0

你好是一个页面...不是一个简单的html网站,它有一个索引,在这种情况下,我们可以指向该域名。这是一个用流星建造的网站:-( – THpubs

+0

我认为你应该指向与example.com相同的地方,并写出将重写url'hello.com /(.*)'为'。/ hello/$ 1'的重写规则 –

回答

5

可以使用proxy_passdirective。只要创建与域hello.com,然后location = /设置相关的新服务器proxy_pass等于http://example.com/hello

server { 
    server_name hello.com; 
    # ... 
    location =/{ 
     proxy_pass http://example.com/hello/; 
    } 

    # serve static content (ugly way) 
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt)$ { 
     proxy_pass http://example.com/hello/$uri$is_args$args; 
    } 

    # serve static content (better way, 
    # but requires collection all assets under the common root) 
    location ~ /static/ { 
     proxy_pass http://example.com/static/; 
    } 
} 

UPD:这里是你的情况的精确解:

server { 
    server_name swimamerica.lk; 

    location =/{ 
     proxy_pass http://killerwhales.lk/swimamerica; 
    } 

    # serve static content (ugly way) - added woff and woff2 extentions 
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt|woff|woff2)$ { 
     proxy_pass http://killerwhales.lk$uri$is_args$args; 
    } 

    # added location for web sockets 
    location ~* sockjs { 
     proxy_pass http://killerwhales.lk$uri$is_args$args; 
    } 
} 
+0

谢谢,但有一个问题...该网站现在尝试加载所有资源(js,css,image等)作为hello域名。例如:'hello.com/main.js',但它们位于'example.com/main.js'。因此,该网站无法加载。 – THpubs

+1

@THpubs,我已经更新了答案。 –

+0

谢谢。我试过了,但仍然不能正常工作 – THpubs

-2

使用proxy_pass指示。只要创建与域hello.com,然后location = /设置proxy_pass等于http://domain.com/hello关联的新服务器:

server { 
    server_name hello.com; 
    # ... 
    location =/{ 
     proxy_pass http://domain.com/hello/; 
    } 

    # serve static content (ugly way) 
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|rss|txt)$ { 
     proxy_pass http://domain.com/hello/$uri$is_args$args; 
    } 

    # serve static content (better way, 
    # but requires collection all assets under the common root) 
    location ~ /static/ { 
     proxy_pass http://domain.com/static/; 
    } 
} 
相关问题