如何将一个域名指向另一个网站的页面?

例如,我在域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" 

你可以使用proxy_pass 指令 。 只需创建一个与域hello.com相关的新服务器,然后为location = / set 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; } } 

使用proxy_pass指令。 只需创建一个与域hello.com相关的新服务器,然后对于location = / set 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/; } }