【问题标题】:nginx access subdomain.domain.com as domain.comnginx 访问 subdomain.domain.com 作为 domain.com
【发布时间】:2014-11-14 21:15:38
【问题描述】:

我是nginx系统的新手,之前,我设法通过subdomain.domain.com(没有端口号)通过this answer的帮助访问subdomain.domain.com:3000

我发现难以实现以下目标:

我想通过domain.com 访问在subdomain.domain.com 中运行的Rails 服务器。即
当有人在浏览器中点击 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;
    }
}

【问题讨论】:

  • 看起来问题更清晰了,需要添加nginx.conf文件。
  • @RobertChristopher 更新了我的 nginx 配置文件。

标签: ruby-on-rails nginx dns http-redirect


【解决方案1】:

您可以为代理设置所需的主机,网址在浏览器中不应更改,但这可以更改代理站点上基于主机名的链接:

proxy_set_header Host subdomain.domain.com;

【讨论】:

    猜你喜欢
    • 2012-07-06
    • 2023-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多