32

我在带有Omnibus 包的专用 Ubuntu 14.04 服务器版本上安装了Gitlab CE

现在我想在 gitlab 旁边安装另外三个虚拟主机。

两个是non-root user运行在两个不同的 node.js Web 应用程序上ports > 1024,第三个是 PHP Web 应用程序,需要从 Web 服务器启动。

有:

  • 8081在( node.js)上运行的私人凉亭注册表
  • 8082在( node.js)上运行的私有 npm 注册表
  • 私人作曲家注册表 ( PHP)

但是Omnibus 听 80并且似乎既不使用 Apache2 也不使用 Nginx,因此我不能使用它们来服务我的 PHP 应用程序和反向代理我的其他两个节点应用程序

Gitlab Omnibus 使用什么服务机制listen 80?我应该如何创建其他三个虚拟主机才能提供以下 vHosts ?

  • gitlab.mycompany.com( :80) -- 已经在使用
  • bower.mycompany.com( :80)
  • npm.mycompany.com( :80)
  • packagist.mycompany.com( :80)
4

2 回答 2

27

由于我不想为 gitlab 更改 nginx 服务器(与其他一些集成),所以最安全的方法是下面的解决方案。

也按照

Gitlab:Ningx =>将自定义设置插入 NGINX 配置

编辑你的 gitlab 的 /etc/gitlab/gitlab.rb :

nano /etc/gitlab/gitlab.rb

并滚动到 nginx['custom_nginx_config'] 并进行如下修改,确保取消注释

# Example: include a directory to scan for additional config files
nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/*.conf;"

创建新的配置目录:

mkdir -p /etc/nginx/conf.d/
nano /etc/nginx/conf.d/new_app.conf

并将内容添加到您的新配置中

# my new app config : /etc/nginx/conf.d/new_app.conf
# set location of new app 
upstream new_app {
  server localhost:1234; # wherever it might be
}
# set the new app server
server {
  listen *:80;
  server_name new_app.mycompany.com;
  server_tokens off;
  access_log  /var/log/new_app_access.log;
  error_log   /var/log/new_app_error.log;
  proxy_set_header Host      $host;
  proxy_set_header X-Real-IP $remote_addr;
  location / { proxy_pass  http://new_app; }
}

并重新配置 gitlab 以插入新设置

gitlab-ctl reconfigure

重启 nginx

gitlab-ctl restart nginx

检查 nginx 错误日志:

tail -f /var/log/gitlab/nginx/error.log
于 2016-09-26T06:11:56.893 回答
26

关于这些

但是 Omnibus 听 80 并且似乎既不使用 Apache2 也不使用 Nginx [ ,因此 ...]

和@stdob 评论:

综合巴士没有使用 nginx 作为网络服务器吗???–

我回应了

我猜不是因为系统中没有安装nginx包......

据实

来自 Gitlab 官方文档:

默认情况下,omnibus-gitlab 将 GitLab 与捆绑的 Nginx 一起安装。

所以是的!

Omnibus 包实际上使用 Nginx !

但它被捆绑在一起,解释了为什么它不需要作为主机操作系统的依赖项安装。

因此是的!Nginx 可以而且应该用于为我的 PHP 应用程序提供服务并反向代理我的其他两个节点应用程序。

那么现在

Omnibus-gitlab 允许通过gitlab-www驻留在同名组中的用户访问网络服务器。要允许外部网络服务器访问 GitLab,需要将外部网络服务器用户添加到gitlab-www组。

要使用另一个 Web 服务器,如 Apache 或现有的 Nginx 安装,您必须执行以下步骤:

通过指定禁用捆绑的 Nginx/etc/gitlab/gitlab.rb

nginx['enable'] = false
# For GitLab CI, use the following:
ci_nginx['enable'] = false

检查非捆绑网络服务器用户的用户名。默认情况下omnibus-gitlab,外部网络服务器用户没有默认设置。您必须在配置中指定外部网络服务器用户用户名!例如,假设网络服务器用户是www-data. 在/etc/gitlab/gitlab.rb集合

web_server['external_users'] = ['www-data']

此设置是一个数组,因此您可以指定多个用户添加到 gitlab-www 组。

运行sudo gitlab-ctl reconfigure以使更改生效。

设置 NGINX 监听地址或地址

默认情况下,NGINX 将接受所有本地 IPv4 地址上的传入连接。您可以更改 中的地址列表/etc/gitlab/gitlab.rb

nginx['listen_addresses'] = ["0.0.0.0", "[::]"] # listen on all IPv4 and IPv6 addresses

对于 GitLab CI,请使用该ci_nginx['listen_addresses']设置。

设置 NGINX 监听端口

默认情况下,NGINX 将监听指定的端口external_url或隐式使用正确的端口(HTTP 为 80,HTTPS 为 443)。如果您在反向代理后面运行 GitLab,您可能希望将侦听端口覆盖为其他端口。例如,要使用端口 8080:

nginx['listen_port'] = 8080

同样,对于 GitLab CI:

ci_nginx['listen_port'] = 8081

支持代理 SSL

默认情况下 NGINX 会自动检测是否使用 SSL if external_url contains https://。如果您在反向代理后面运行 GitLab,您可能希望将其保留external_url为 HTTPS 地址,但在内部通过 HTTP 与 GitLab NGINX 通信。为此,您可以使用以下listen_https选项禁用 HTTPS:

nginx['listen_https'] = false

同样,对于 GitLab CI:

ci_nginx['listen_https'] = false

请注意,您可能需要配置反向代理以将某些标头(例如,、、、HostX-Forwarded-Ssl转发到 GitLab。X-Forwarded-ForX-Forwarded-Port

如果您忘记了这一步,您可能会看到不正确的重定向或错误(例如“422 Unprocessable Entity”、“无法验证 CSRF 令牌真实性”)。有关更多信息,请参阅:

要更进一步,您可以关注https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#using-a-non-bundled-web-server上的官方文档

配置我们的 gitlab 虚拟主机

安装 Phusion 乘客

我们需要在操作系统中全局安装 ruby

$ sudo apt-get update 
$ sudo apt-get install ruby
$ sudo gem install passenger

使用乘客模块重新编译 nginx

例如, nginxApache2不能即时插入二进制模块。必须为您要添加的每个新插件重新编译它。

Phusion 乘客开发团队努力提供“乘客的捆绑 nginx 版本”:使用乘客插件编译的 nginx 箱。

所以,让我们使用它:

要求:我们需要打开我们的TCP端口11371APT key端口)。

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
$ sudo apt-get install apt-transport-https ca-certificates
创造passenger.list
$ sudo nano /etc/apt/sources.list.d/passenger.list

用这些线

# Ubuntu 14.04
deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main

为您的 ubuntu 版本使用正确的存储库。以 Ubuntu 15.04 为例:deb https://oss-binaries.phusionpassenger.com/apt/passengervivid main

编辑权限:

$ sudo chown root: /etc/apt/sources.list.d/passenger.list
$ sudo chmod 600 /etc/apt/sources.list.d/passenger.list

更新包列表:

$ sudo apt-get update

允许它作为unattended-upgrades

$ sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

在文件顶部查找或创建此配置块:

// Automatically upgrade packages from these (origin:archive) pairs
Unattended-Upgrade::Allowed-Origins {

  // you may have some instructions here

};

添加以下内容:

// Automatically upgrade packages from these (origin:archive) pairs
Unattended-Upgrade::Allowed-Origins {

  // you may have some instructions here

  // To check "Origin:" and "Suite:", you could use e.g.:
  // grep "Origin\|Suite" /var/lib/apt/lists/oss-binaries.phusionpassenger.com*
    "Phusion:stable";

};

现在(重新)安装nginx-extrapassenger

$ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak_"$(date +%Y-%m-%d_%H:%M)"
$ sudo apt-get install nginx-extras passenger

配置它

取消注释文件中的passenger_rootandpassenger_ruby指令/etc/nginx/nginx.conf

$ sudo nano /etc/nginx/nginx.conf

...获得类似的东西:

##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;

创建 nginx 站点配置(虚拟主机 conf)

$ nano /etc/nginx/sites-available/gitlab.conf

server {
  listen *:80;
  server_name gitlab.mycompany.com;
  server_tokens off;
  root /opt/gitlab/embedded/service/gitlab-rails/public;

  client_max_body_size 250m;
  access_log  /var/log/gitlab/nginx/gitlab_access.log;
  error_log   /var/log/gitlab/nginx/gitlab_error.log;

  # Ensure Passenger uses the bundled Ruby version
  passenger_ruby /opt/gitlab/embedded/bin/ruby;

  # Correct the $PATH variable to included packaged executables
  passenger_env_var PATH "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/usr/local/bin:/usr/bin:/bin";

  # Make sure Passenger runs as the correct user and group to
  # prevent permission issues
  passenger_user git;
  passenger_group git;

  # Enable Passenger & keep at least one instance running at all times
  passenger_enabled on;
  passenger_min_instances 1;

  error_page 502 /502.html;
}

现在我们可以启用它:

$ sudo ln -s /etc/nginx/sites-available/gitlab.cong /etc/nginx/sites-enabled/

nginx没有原生的a2ensite等价物,所以我们使用ln,但如果你愿意,github 上有一个项目: nginx_ensitenginx_ensite 和 nginx_dissite 用于快速启用和禁用虚拟主机

这是一个 shell (Bash) 脚本,它为 nginx 复制 Debian a2ensite 和 a2dissite,用于在 Apache 2.2/2.4 中启用和禁用站点作为虚拟主机。

完成了:-)。最后重启nginx

$ sudo service nginx restart

有了这个新配置,你可以在 gitlab 旁边运行其他虚拟主机来提供你想要的服务

只需在/etc/nginx/sites-available.

就我而言,我在同一主机上以这种方式运行和服务:

例如,服务npm.mycompany.com

为日志创建一个目录:

$ sudo mkdir -p /var/log/private-npm/nginx/

并填写一个新的 vhost 配置文件:

$ sudo nano /etc/nginx/sites-available/npm.conf

有了这个配置

server {
  listen *:80;
  server_name npm.mycompany.com

  client_max_body_size 5m;
  access_log  /var/log/private-npm/nginx/npm_access.log;
  error_log   /var/log/private-npm/nginx/npm_error.log;

  location / {
    proxy_pass http://localhost:8082;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

然后启用它并重新启动它:

$ sudo ln -s /etc/nginx/sites-available/npm.conf /etc/nginx/sites-enabled/
$ sudo service nginx restart
于 2015-08-03T06:51:11.367 回答