yok*_*dev 30 nginx gitlab gitlab-ci
您好我已经使用此https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#installation安装了Gitlab
现在我想使用nginx来提供除gitlab应用程序以外的其他内容我该怎么做呢
更新(忘了提到我在Red Hat 6.5,Debian/Ubuntu解决方案欢迎下运行它)
小智 7
我在这里使用
- gitlab.example.com to serve gitlab.example.com over https.
- example.com over http to serve another content other than gitlab application.
Run Code Online (Sandbox Code Playgroud)
从deb软件包安装的Gitlab正在使用chef来配置ngnix,因此你必须修改自己的主厨并将新的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"),
})
Run Code Online (Sandbox Code Playgroud)
至:
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"),
})
Run Code Online (Sandbox Code Playgroud)
将此添加到同一文件:
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
Run Code Online (Sandbox Code Playgroud)
然后在模板目录(/ 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;
}
Run Code Online (Sandbox Code Playgroud)
你必须在(/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
Run Code Online (Sandbox Code Playgroud)
添加include <%= @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 %>;
}
Run Code Online (Sandbox Code Playgroud)
完成所有这些更改后:
gitlab-ctl reconfigure
gitlab-ctl restart
Run Code Online (Sandbox Code Playgroud)
vndr的上述解决方案可行,但在https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md上,它说:
将自定义设置插入NGINX配置
如果需要将自定义设置添加到NGINX配置中,例如包括现有服务器块,则可以使用以下设置.
示例:包含扫描其他配置文件的目录nginx ['custom_nginx_config'] ="include /etc/nginx/conf.d/*.conf;"
那么让我们检查你的/opt/gitlab/embedded/cookbooks/gitlab/templates/default/nginx.conf.erb,看它是否包含:<%= @custom_nginx_config%> (它看起来像当前的gitlab-7.5.3_omnibus.5.2 .1.ci-1.el6.x86_64.rpm不包括它)
如果没有,那么只需将其添加到包含<%= @gitlab_http_config%>的行上方; 喜欢:
<%= @custom_nginx_config %>
include <%= @gitlab_http_config %>;
Run Code Online (Sandbox Code Playgroud)
然后打开/etc/gitlab/gitlab.rb添加:nginx ['custom_nginx_config'] ="include /etc/nginx/conf.d/*.conf;"
我们可以简单地通过添加:include /etc/nginx/conf.d/*.conf; 而是<%= @custom_nginx_config%>
然后在/etc/nginx/conf.d/和gitlab-ctl reconfigure中创建普通的nginx .conf文件
由于我不想更改 gitlab Nginx 服务器的配置,也不想安装/配置另一个 Nginx 并确保 gitlab 能够在重大更新中幸存下来,因此我来到以下Gitlab Omnibus 包的解决方案。
也按照
Gitlab:Ningx =>将自定义设置插入到 NGINX 配置中
编辑 gitlab 的 /etc/gitlab/gitlab.rb:
nano /etc/gitlab/gitlab.rb
Run Code Online (Sandbox Code Playgroud)
并滚动到 nginx['custom_nginx_config'] 并修改如下,确保取消注释
# Example: include a directory to scan for additional config files
nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/*.conf;"
Run Code Online (Sandbox Code Playgroud)
创建新的配置目录:
mkdir -p /etc/nginx/conf.d/
nano /etc/nginx/conf.d/new_app.conf
Run Code Online (Sandbox Code Playgroud)
并将内容添加到您的新配置:/etc/nginx/conf.d/new_app.conf
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;
root /var/www/html/new_app/;
index index.html index.htm;
}
Run Code Online (Sandbox Code Playgroud)
并重新配置 gitlab 以插入新设置
gitlab-ctl reconfigure
Run Code Online (Sandbox Code Playgroud)
在更改配置或在 /etc/nginx/conf.d 中添加更多配置后重新启动 nginx:
gitlab-ctl restart nginx
Run Code Online (Sandbox Code Playgroud)
检查nginx错误日志:
tail -f /var/log/gitlab/nginx/error.log
Run Code Online (Sandbox Code Playgroud)
并参阅/sf/answers/2778705401/以重定向到另一个应用程序服务器。
我已经尝试了这两种方法,对我来说最有效的一种方法是在 gitlab 的内置方法之上放置一个干净的 NGINX。从长远来看,它更容易/方便。
根据您的需求,这里有一些必须首先到位的 关键事项:
以下是要遵循的主要步骤,请记住,根据您的需求,这可能意味着需要进行更多调整,而且这是Ubuntu Server 14.04。
首先停用主Nginx(与omnibus捆绑在一起的Nginx)编辑/etc/gitlab/gitlab.rb
nginx['enable'] = false
ci_nginx['enable'] = false
关于上一步:有时安装程序不会创建 sites-enabled/和sites-available/文件夹,创建它们,并确保将它们包含在/etc/nginx/nginx.conf文件中
include /etc/nginx/sites-enabled/*.conf;
这是我的会议:
`upstream gitlab-workhorse {
server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
## Normal HTTP host
server {
## Either remove "default_server" from the listen line below,
## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
## to be served if you visit any address that your server responds to, eg.
## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
#listen 0.0.0.0:80 default_server;
listen 0.0.0.0:80 ;
# listen [::]:80 default_server;
server_name gitlab.mycompany.com; ## Replace this with something like gitlab.example.com
server_tokens off; ## Don't show the nginx version number, a security best practice
root /opt/gitlab/embedded/service/gitlab-rails/public;
## See app/controllers/application_controller.rb for headers set
## Individual nginx logs for this GitLab vhost
access_log /var/log/nginx/gitlab.access.log;
error_log /var/log/nginx/gitlab.error.log;
location / {
client_max_body_size 0;
gzip off;
## https://github.com/gitlabhq/gitlabhq/issues/694
## Some requests take more than 30 seconds.
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://gitlab-workhorse;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到更多配置详细信息更多选项
重新启动/重新加载 nginx
sudo service nginx restart
重新启动 gitlabomnibus 并检查你的 Gitlab 配置
sudo gitlab-ctl reconfigure
sudo gitlab-ctl tail
(只是为了检查你的gitlab配置是否有问题)
在/etc/nginx/sites-available/中添加所需的额外(任意数量)服务器配置,最终当高兴/准备好时将链接添加到/etc/nginx/sites-enabled/
这是另一个应用程序的另一个示例
upstream app_server {
server 127.0.0.1:9080 fail_timeout=0;
}
server {
listen 80;
server_name jenkins.mycompany.com;
access_log /var/log/nginx/jenkins.access.log;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)请记住始终重新启动/重新加载 nginx,以便您看到更改。
sudo service nginx restart
检查日志以防出现问题/var/log/nginx/anysites*.log
请注意,这里我们使用具有不同端口的上游,并且名称(它们存在/是真实的/在贵公司的域中注册)都指向相同的IP地址,这意味着NIGNX会来找到相同的IP地址,但是它不会因为上游的不同端口而中断,这非常重要
这就是我的配置现在的工作方式,我的 Gitlab 或任何其他应用程序都没有遇到任何问题。
所以希望这对任何人都有帮助。
归档时间: |
|
查看次数: |
11365 次 |
最近记录: |