在Apache上托管主域,在Nginx上托管一些子域

时间:2013-08-01 15:37:11

标签: apache nginx subdomain gitlab linode

我最近买了一个linode 1GB计划。安装了Apache,让我的网站启动并运行。 但是我在服务器上安装了gitlab并将其映射到子域。由于安装指南建议使用Nginx作为服务器,我安装它并在端口80上运行。目前我的apache没有运行,因为存在端口冲突。 但我通过编辑/etc/apache2/ports.conf文件并指示apache在不同的端口上提供服务来修复它。 现在当我访问指向端口(8000)的主域并且使用apache时不显示。 gitlab安装在http://gitlab.myserver.com,我可以访问它。但如果我尝试导航到http://myserver.com,我会收到http://gitlab.myserver.com的内容

我在Nginx下的gitlab配置如下:

# GITLAB
# Maintainer: @randx
# App Version: 5.0

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

server {
  listen my_server_ip default_server;  # e.g., listen 192.168.1.1:80; In most    cases *:80 is a good idea
  server_name gitlab.myserver.com;         # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice
  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 800; # 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;
 }
}

myserver.com的我的Apache配置如下:

# domain: myserver.com
# public: /home/me/public/myserver.com/

<VirtualHost *:8000>
 # Admin email, Server Name (domain name), and any aliases
 ServerAdmin webmaster@myserver.com
 ServerName  www.myserver.com
 ServerAlias myserver.com

 # Index file and Document Root (where the public files are located)
 DirectoryIndex index.html index.php
 DocumentRoot /home/me/public/myserver.com/public

 # Log file locations
 LogLevel warn
 ErrorLog  /home/me/public/myserver.com/log/error.log
 CustomLog /home/me/public/myserver.com/log/access.log combined
</VirtualHost>

我哪里错了?

2 个答案:

答案 0 :(得分:1)

一个好的解决方案是继续在端口80上运行Nginx,同时向Nginx添加代理指令,作为在Apache上运行的特定域的代理。 Nginx配置示例:

server {
    server_name  www.myserver.com;
    server_name myserver.com;

   location / {
      proxy_pass http://127.0.0.1:8000;
   }
}

我自己这样做,而且效果很好。

答案 1 :(得分:0)

我解决了这个问题。问题在于我的gitlab配置中的以下行:

server {
  listen my_ip default_server;
  server_name gitlab.myserver.com;         # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice
  root /home/git/gitlab/public;
  ......
}

我将此更改为以下内容:

server {
      listen 80;
      server_name gitlab.myserver.com;         # e.g., server_name source.example.com;
      server_tokens off;     # don't show the version number, a security best practice
      root /home/git/gitlab/public;
      ......
    }

我通过使用proxy_pass

按照你的指示通过nginx在apache上提供站点服务

非常感谢.. 干杯....