使用gitlab的nginx来提供另一个应用程序

 -不想醒来-县 发布于 2023-01-11 11:32

您好我已经使用此https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#installation安装了Gitlab

现在我想使用nginx来提供除gitlab应用程序以外的其他内容我该怎么做呢

我需要修改的配置文件在哪里

如何指向像/ var/www这样的目录,以便nginx知道这是另一个应用程序的根目录.

更新(忘了提到我在Red Hat 6.5,Debian/Ubuntu解决方案欢迎下运行它)

2 个回答
  • 我在这里使用

    - 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,因此你必须修改自己的主厨并将新的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
    

    添加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 %>;
    }
    

    完成所有这些更改后:

    gitlab-ctl reconfigure
    gitlab-ctl restart
    

    2023-01-11 11:33 回答
  • 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 %>;
    

    然后打开/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文件

    2023-01-11 11:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有