我使用Omnibus软件包在专用的Ubuntu 14.04服务器版上安装了Gitlab CE 。
两个是在两个不同的ports > 1024
上运行的non-root user
启动的node.js web应用程序ports > 1024
,第三个是需要启动web服务器的PHP web应用程序。
有:
8081
( node.js
)上的私人凉亭registry 8082
( node.js
)上运行的私人npmregistry PHP
) 但Omnibus听80 ,似乎既不使用Apache2或Nginx, 因此我不能使用它们来服务我的PHP应用程序,并反向代理我的两个其他节点的应用程序 。
什么服务机制Gitlab Omnibus用来
listen 80
? 我应该如何创build其他三个虚拟主机来提供以下vHosts?
gitlab.mycompany.com
(:80
) – 已经在使用bower.mycompany.com
(:80
)npm.mycompany.com
(:80
)packagist.mycompany.com
(:80
)
但是Omnibus听80,似乎不使用Apache2或Nginx [ ,因此…] 。
和@stdob评论:
是否omnibus不使用nginx作为Web服务器? –
我很回答
我想不是因为nginx包没有安装在系统中…
从Gitlab官方文档:
默认情况下,omnibus-gitlab将捆绑Nginx安装GitLab。
所以是的!
Omnibus包实际上使用Nginx!
但它是捆绑的,解释了为什么它不需要作为从主机操作系统的依赖安装。
因此是! Nginx可以,而且应该用来服务我的PHP应用程序,并反向代理我的另外两个节点应用程序。
Omnibus-gitlab允许通过用户gitlab-www
访问web服务器,该用户驻留在具有相同名称的组中。 要允许外部Web服务器访问GitLab,需要将外部Web服务器用户添加到gitlab-www
组中。
要使用其他Web服务器(如Apache或现有的Nginx安装),您必须执行以下步骤:
在/etc/gitlab/gitlab.rb
指定禁用绑定的Nginx
nginx['enable'] = false # For GitLab CI, use the following: ci_nginx['enable'] = false
检查非捆绑网络服务器用户的用户名。 默认情况下, omnibus-gitlab
没有外部web服务器用户的默认设置。 您必须在配置中指定外部Web服务器用户名称! 比如说,web服务器用户是www-data
。 在/etc/gitlab/gitlab.rb
设置
web_server['external_users'] = ['www-data']
这个设置是一个数组,所以你可以指定多个用户添加到gitlab-www组。
运行sudo gitlab-ctl reconfigure
使更改生效。
默认情况下,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将监听external_url
指定的端口,或者隐式使用正确的端口(80代表HTTP,443代表HTTPS)。 如果您在反向代理的后面运行GitLab,则可能需要将监听端口重写为其他内容。 例如,要使用端口8080:
nginx['listen_port'] = 8080
同样,对于GitLab CI:
ci_nginx['listen_port'] = 8081
默认情况下,如果external_url
包含https://
NGINX将自动检测是否使用SSL。 如果您在反向代理的后面运行GitLab,您可能希望将external_url
作为HTTPS地址保留,但通过HTTP与GitLab NGINX进行内部通信。 为此,您可以使用listen_https
选项禁用HTTPS:
nginx['listen_https'] = false
同样,对于GitLab CI:
ci_nginx['listen_https'] = false
请注意,您可能需要配置您的反向代理以将某些标题(例如Host
, X-Forwarded-Ssl
, X-Forwarded-For
, X-Forwarded-Port
) X-Forwarded-Port
到GitLab。
如果您忘记了此步骤,您可能会看到不正确的重定向或错误(例如“422无法处理的实体”,“无法验证CSRF令牌的真实性”)。 有关更多信息,请参阅:
要进一步您可以按照官方文档在https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#using-a-non-bundled-web-server
我们需要在操作系统中全局安装ruby(捆绑ruby的总括运行gitlab)
$ sudo apt-get update $ sudo apt-get install ruby $ sudo gem install passenger
例如,而不是Apache2
,nginx不能被二进制模块即时插入。 必须重新编译每个要添加的新插件。
Phusion乘客开发团队努力提供“ 乘客捆绑nginx版本 ” 的说法:用乘客插件编译nginx bin。
所以,让我们使用它:
要求 :我们需要打开我们的
TCP
端口11371
(APT 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
与这些lignes
# Ubuntu 14.04 deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main
使用正确的回购你的Ubuntu版本。 以Ubuntu 15.04为例:deb https://oss-binaries.phusionpassenger.com/apt/passenger vivid 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 eg: // grep "Origin\|Suite" /var/lib/apt/lists/oss-binaries.phusionpassenger.com* "Phusion:stable"; };
nginx-extra
和passenger
: $ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak_"$(date +%Y-%m-%d_%H:%M)" $ sudo apt-get install nginx-extras passenger
取消/etc/nginx/nginx.conf
文件中的passenger_root
和passenger_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;
$ 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_ensite : nginx_ensite和nginx_dissite,用于快速虚拟主机启用和禁用这是一个shell(Bash)脚本,用于复制nginx的Debian a2ensite和a2dissite,用于在Apache 2.2 / 2.4中启用和禁用站点作为虚拟主机。
$ sudo service nginx restart
只需在/etc/nginx/sites-available
创建新的配置。
就我而言,我在同一台主机上运行和服务:
node.js
编写的私有npm注册表 node.js
编写的私人注册表注册表 例如,要服务npm.mycompany.com
:
为日志创建一个目录:
$ 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
因为我不想更改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