我在这里使用
- gitlab.example.com to serve gitlab.example.com over https.
- example.com over http to serve another content other than gitlab application.
从 deb 包安装的 Gitlab 正在使用 chef 来配置 ngnix,因此您必须修改 chef recipies 并将新的 vhost 模板添加到 chef cookbooks 目录
你可以在这里找到所有的厨师食谱:/opt/gitlab/embedded/cookbooks/gitlab/
打开/opt/gitlab/embedded/cookbooks/gitlab/recipes/nginx.rb
改变:
nginx_vars = node['gitlab']['nginx'].to_hash.merge({
:gitlab_http_config => File.join(nginx_etc_dir, "gitlab-http.conf"),
})
至:
nginx_vars = node['gitlab']['nginx'].to_hash.merge({
:gitlab_http_config => File.join(nginx_etc_dir, "gitlab-http.conf"),
:examplecom_http_config => File.join(nginx_etc_dir, "examplecom-http.conf"),
})
将此添加到同一文件中:
template nginx_vars[:examplecom_http_config] do
source "nginx-examplecom-http.conf.erb"
owner "root"
group "root"
mode "0644"
variables(nginx_vars.merge(
{
:fqdn => "example.com",
:port => 80,
}
))
notifies :restart, 'service[nginx]' if OmnibusHelper.should_notify?("nginx")
end
然后在模板目录(/opt/gitlab/embedded/cookbooks/gitlab/templates/default)中,创建nginx vhost模板文件(nginx-examplecom-http.conf.erb)并在其中添加:
server {
listen <%= @listen_address %>:<%= @port %>;
server_name <%= @fqdn %>;
root /var/www/example.com;
access_log <%= @log_directory %>/examplecom_access.log;
error_log <%= @log_directory %>/examplecom_error.log;
location /var/www/example.com {
# 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;
}
error_page 502 /502.html;
}
你必须在(/etc/gitlab/gitlab.rb)中设置nginx['redirect_http_to_https'] = false :
external_url "https://gitlab.example.com"
gitlab_rails['gitlab_email_from'] = "info@example.com"
gitlab_rails['gitlab_support_email'] = "support@example.com"
nginx['redirect_http_to_https'] = false
nginx['ssl_certificate'] = "/etc/gitlab/ssl/ssl-unified.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/ssl.key"
gitlab_rails['gitlab_default_projects_limit'] = 10
添加包括 <%= @examplecom_http_config %>; 进入 /opt/gitlab/embedded/cookbooks/gitlab/templates/default/nginx.conf.erb :
http {
sendfile <%= @sendfile %>;
tcp_nopush <%= @tcp_nopush %>;
tcp_nodelay <%= @tcp_nodelay %>;
keepalive_timeout <%= @keepalive_timeout %>;
gzip <%= @gzip %>;
gzip_http_version <%= @gzip_http_version %>;
gzip_comp_level <%= @gzip_comp_level %>;
gzip_proxied <%= @gzip_proxied %>;
gzip_types <%= @gzip_types.join(' ') %>;
include /opt/gitlab/embedded/conf/mime.types;
include <%= @gitlab_http_config %>;
include <%= @examplecom_http_config %>;
}
在所有这些更改运行之后:
gitlab-ctl reconfigure
gitlab-ctl restart