Nginx 如何为Gitlab Omnibus服务器旁边的其他vHost提供服务?[完整的分步解决方案]

Nginx 如何为Gitlab Omnibus服务器旁边的其他vHost提供服务?[完整的分步解决方案],nginx,webserver,virtualhost,gitlab,gitlab-omnibus,Nginx,Webserver,Virtualhost,Gitlab,Gitlab Omnibus,我在专用的Ubuntu 14.04服务器版上安装了Gitlab CE,附带综合软件包 现在我想在gitlab旁边安装另外三个虚拟主机 两个是node.js web应用程序,由运行在两个不同的端口>1024上的非root用户启动,第三个是PHP web应用程序,需要从中启动web服务器 有: 运行在8081(node.js)上的私有bower注册表 运行在8082(node.js)上的专用npm注册表 专用编写器注册表(PHP) 但是,Omnibus listen 80似乎既不使用Apache

我在专用的Ubuntu 14.04服务器版上安装了Gitlab CE,附带综合软件包

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

两个是node.js web应用程序,由运行在两个不同的
端口>1024
上的
非root用户启动,第三个是PHP web应用程序,需要从中启动web服务器

有:

  • 运行在
    8081
    node.js
    )上的私有bower注册表
  • 运行在
    8082
    node.js
    )上的专用npm注册表
  • 专用编写器注册表(
    PHP
但是,Omnibus listen 80似乎既不使用Apache2也不使用Nginx,因此我不能使用它们来服务我的PHP应用程序,也不能反向代理我的另外两个节点应用程序

Gitlab Omnibus使用什么来收听80? 我应该如何创建其他三个虚拟主机来提供以下vhost

  • gitlab.mycompany.com
    :80
    )--已在使用中
  • bower.mycompany.com
    :80
  • npm.mycompany.com
    :80
  • packagist.mycompany.com
    :80
关于这些 但是Omnibus listen 80似乎既不使用Apache2也不使用Nginx[,因此…]

和@stdob评论:


omnibus是否未将nginx用作web服务器??——

我的回答是什么


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

事实上 从Gitlab官方文档:

默认情况下,omnibus gitlab安装gitlab和捆绑的Nginx

是的

综合包实际上使用了Nginx

但它是捆绑的,这解释了为什么它不需要作为主机操作系统的依赖项安装

因此是的Nginx可以而且应该用于为我的PHP应用提供服务,并反向代理我的另外两个节点应用。

那么现在 Omnibus gitlab允许通过驻留在其中的用户
gitlab www
访问Web服务器 在具有相同名称的组中。允许外部Web服务器访问 GitLab,需要添加外部Web服务器用户
GitLab www

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

通过在
/etc/gitlab/gitlab.rb

nginx['enable'] = false
# For GitLab CI, use the following:
ci_nginx['enable'] = false
检查未绑定的web服务器用户的用户名。默认情况下,
omnibus gitlab
没有外部Web服务器用户的默认设置。 您必须在配置中指定外部Web服务器用户用户名! 例如,假设webserver用户是
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\u nginx['listen\u addresses']
设置

设置NGINX侦听端口 默认情况下,NGINX将在
external\u url
或 隐式使用正确的端口(80代表HTTP,443代表HTTPS)。如果你正在跑步 GitLab位于反向代理之后,您可能希望覆盖侦听端口以 还有别的。例如,要使用端口8080:

nginx['listen_port'] = 8080
同样,对于GitLab CI:

ci_nginx['listen_port'] = 8081
ci_nginx['listen_https'] = false
支持代理SSL 默认情况下,如果
external\u url
包含
https://
。如果您在反向代理后运行GitLab,则 可能希望将
外部url
保留为HTTPS地址,但与 GitLab NGINX通过HTTP在内部运行。为此,可以使用禁用HTTPS
listen\u https
选项:

nginx['listen_https'] = false
同样,对于GitLab CI:

ci_nginx['listen_port'] = 8081
ci_nginx['listen_https'] = false
请注意,您可能需要配置反向代理以转发某些 发送到GitLab的头文件(例如,
主机
X-Forwarded-Ssl
X-Forwarded-For
X-Forwarded-Port

您可能会看到不正确的重定向或错误(例如“422不可处理实体”, 如果忘记此步骤,“无法验证CSRF令牌真实性”)。更多 详情见:

要进一步了解,您可以按照以下官方文件进行操作:

配置gitlab虚拟主机 安装Phusion乘用车 我们需要在操作系统中全局安装ruby(gitlab在omnibus中运行,附带一个捆绑的ruby)

$ sudo apt-get update 
$ sudo apt-get install ruby
$ sudo gem install passenger
使用乘客模块重新编译nginx 例如,nginx不能动态插入二进制模块,而不是Apache2。它必须为您要添加的每个新插件重新编译

Phusion乘客开发团队努力提供“使用乘客插件编译的nginx bins”

因此,让我们使用它:

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

正在创建乘客列表
$ sudo nano /etc/apt/sources.list.d/passenger.list
用这些木线

# Ubuntu 14.04
deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main
为你的ubuntu版本使用正确的repo。例如,对于Ubuntu 15.04: 黛布·维克梅因酒店

编辑权限:

$ sudo chown root: /etc/apt/sources.list.d/passenger.list
$ sudo chmod 600 /etc/apt/sources.list.d/passenger.list
更新包列表:

$ sudo apt-get update
允许它作为无人值守的升级

$ 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 extra
passenger
: 配置它 取消注释
/etc/nginx/nginx.conf
文件中的
passenger\u root
passenger\u ruby
指令:

$ 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;
$ 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/
$ sudo service nginx restart
$ sudo mkdir -p /var/log/private-npm/nginx/
$ 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
nano /etc/gitlab/gitlab.rb
# 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-ctl reconfigure
gitlab-ctl restart nginx
tail -f /var/log/gitlab/nginx/error.log