我是nginx系统的新手,以前,我通过subdomain.domain.com(没有端口号)访问subdomain.domain.com:3000。通过this answer的帮助。
我发现很难做到以下几点:
我想通过subdomain.domain.com通过domain.com访问我的Rails服务器。i.e
当有人在浏览器中点击url domain.com时,它应该充当subdomain.domain.com,但是url不应该更改它的浏览器。
有人能帮我吗?我怎样才能做到?
我已经注释掉了/etc/nginx/sites-enabled/default中的默认设置,并在/etc/nginx/sites-enabled/myblog中创建了自己的设置如下:
upstream my-app-cluster
{
server blog.budhram.com:3000;
}
server
{
listen 80;
server_name budhram.com;
# above not working but if used blog.budhram.com then working but not expected
# rails app public folder path
root /home/ubuntu/myblog/public;
# rails app log file path
access_log /home/ubuntu/myblog/log/development.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://my-app-cluster;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}发布于 2014-09-20 12:57:01
您可以为代理设置所需的主机,url不应在浏览器中更改,但这可以更改代理站点上基于主机名的链接:
proxy_set_header Host subdomain.domain.com;https://stackoverflow.com/questions/25948104
复制相似问题