Nginx 如何将域指向另一个网站';s页?

Nginx 如何将域指向另一个网站';s页?,nginx,dns,Nginx,Dns,例如,我在域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] "GE

例如,我在域
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\u pass
。只需创建一个与域
hello.com
关联的新服务器,然后为
location=/
设置
proxy\u 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/;
    }
}
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/;
    }
}
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\u pass
指令。只需创建一个与域
hello.com
关联的新服务器,然后为
location=/
设置
proxy\u pass
等于
http://domain.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/;
    }
}
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/;
    }
}

如果
hello
是目录,为什么不为该域设置服务器?hello是一个页面。。。不是一个简单的html站点,它有一个索引,在这种情况下,我们可以指向域。这是一个使用meteor:-(我认为你应该指向example.com的同一个地方,编写重写规则,将url
hello.com/(.*)
重写为
/hello/$1
。谢谢,但有一个问题……该网站现在尝试加载所有资源(js、css、图像等)作为hello domain.Example:
hello.com/main.js
但它们在
Example.com/main.js
下。因此,站点无法加载。nginx访问/错误日志中有什么内容?浏览器网络控制台是什么样子的?错误日志中没有错误。我只是添加了访问日志:-)不客气,但这是我听过的最糟糕的想法:-)使用重写规则不是更好吗?@THpubs请阅读。