【问题标题】:Nginx showing subdomain's contents as root domainNginx 将子域的内容显示为根域
【发布时间】:2013-04-06 16:45:08
【问题描述】:

我正在使用 Nginx 在我的服务器上运行 Gitlab,它在 git.mysite.com 上运行良好。但是,当我访问根域时,不是在 /usr/share/nginx/www 中显示 index.html 文件,而是在 /home/gitlab/gitlab 中显示 Gitlab。

我该如何解决这个问题?

默认(/etc/nginx/sites-available/default)

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    server_name mysite.com;

    location / {
        try_files $uri $uri/ /index.html;
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    location ~ /\.ht {
        deny all;
    }
}

gitlab (/etc/nginx/sites-available/gitlab)

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen 198.199.70.76:80 default_server;
  server_name git.mysite.com;
  root /home/git/gitlab/public;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://gitlab;
  }
}

【问题讨论】:

    标签: nginx subdomain gitlab


    【解决方案1】:

    您想更改您的子域以侦听端口 80,而不是 default_server。尝试使用这一行:

    listen 80;
    

    代替:

    listen 198.199.70.76:80 default_server;
    

    【讨论】:

      【解决方案2】:

      两个配置都在侦听端口 80,而 gitlab 一个(直接来自 Gitlab recipe,移动到主 gitlab 存储库:gitlab.com/gitlab-org/gitlab-ce/lib/support/nginx/gitlab)用于从“/”访问 GitLab 服务器:http://198.199.70.76:80/返回 GitLab。

      只有无法解析为 198.199.70.76 的查询才会使用第一个配置 (index.html)。
      例如,如果在服务器上执行,http://localhost/ 将起作用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-17
        • 2016-11-05
        • 1970-01-01
        • 2013-05-09
        • 2012-11-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多