nginx - 子域、nginx 和 Godaddy

标签 nginx subdomain

以下是先决条件:

  • 我已注册域名example.com在godaddy。
  • 我在 8080 上运行 Tomcat端口与几个应用程序。 8080端口对世界是隐藏的。
  • 我要 map subdomain.example.comserver:8080/subdomain .我希望将来可以进行类似的映射(例如 subdomain2.example.comserver:8080/anotherContext )。
  • example.com应该映射到 server:8080/mainPageApp
  • 所有其他应用程序应该可以通过它们的上下文访问:example.com/app -> server:8080/app .

  • 目前我只配置了godaddy(不知道这样好不好):

    Godaddy domain config

    在这种情况下,你能帮我配置 nginx 吗?这是我的,但它发送无限重定向:
    server {
        listen       80;
        server_name  localhost;
    
        location / {
            root   html;
            index  index.html;
        }
    }
    server {
        listen       80;
        server_name  subdomain.localhost;
    
        location / {
            proxy_pass http://127.0.0.1:8080/subdomain;
        }
    }
    

    最佳答案

    好的。我得到了这份工作。不确定解决方案是否正确,但是:

    首先,我需要在 Tomcat 中设置一个子域。 Here is the answer I was inspired with.

    <Host name="subdomain.example.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
        <Context path="" docBase="subdomain" />
    </Host>
    

    然后,使用以下命令配置 nginx:
    server {
        listen       80;
        server_name  example.com;
    
        location / {
            root   /path/to/domain/root;
            index  index.html;
        }
    }
    
    server {
        listen       80;
        server_name  subdomain.example.com;
    
        location / {
            proxy_pass        http://subdomain.example.com:8080;
            proxy_set_header  Host             $http_host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
    }
    

    域配置仍然与问题相同 - 这很好。

    最后我把 subdomain.warwebapp我的 Tomcat 目录,它就像一个魅力!

    关于nginx - 子域、nginx 和 Godaddy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15543350/

    相关文章:

    google-chrome-extension - 谷歌加共享 : image and description not coming

    c - 使用msg_accrights在进程之间发送&fd是一个bug吗?

    javascript - 通过 https 的 SSE 不工作

    ruby-on-rails - Rails 应用程序在使用 Unicorn/nginx 组合的 DigitalOcean 上没有响应

    javascript - jQuery 插件不适用于子域

    .htaccess - 使用 htaccess 将所有流量从 root 重定向到特定的子域页面

    php - 带有 Nginx 1.6.2 和 PHP 5.6.4 的 Ubuntu 14.04 上的 502 Bad Gateway

    django - Nginx 可以访问 memcached 来检查某个值以确定重定向到哪里吗?

    security - 使用 htaccess 重定向子域并保留 URL

    php - 将域重定向到不同的 .php 文件