Skip to content
Snippets Groups Projects

support for running in non-root directory/path (RAILS_RELATIVE_URL_ROOT)

Merged gitlab-qa-bot requested to merge github/fork/frohoff/config-improvements into master

Created by: frohoff

I've made some small changes to more robustly and generically allow running gitlab in non-root context-path (i.e. /gitlab) for hostname (and therefore SSL cert) multitenancy. I've been running it in this configuration with apache+mod_proxy and unicorn at work for a couple weeks and everything seems to work, including links in emails, but it's possible there's some darker corners of the app were missed.

I found that in at least some cases executing bundle exec rake assets:clean was required to make sure paths embedded within assets (css urls, etc) were regenerated properly.

Edit: To be clear, this requires that ENV['RAILS_RELATIVE_URL_ROOT'] be specified in config/unicorn.rb, config/environments/*.rb, or elsewhere, as well as a matching "relative_url_root" item in config/gitlab.yml.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Created by: frohoff

    This should resolve #1950 (closed)

    By Administrator on 2012-12-03T22:21:38 (imported from GitLab project)

    By Administrator on 2012-12-03T22:21:38 (imported from GitLab)

  • Created by: riyad

    +1

    By Administrator on 2012-12-04T22:19:23 (imported from GitLab project)

    By Administrator on 2012-12-04T22:19:23 (imported from GitLab)

  • Created by: frohoff

    To be clear, this requires that ENV['RAILS_RELATIVE_URL_ROOT'] be specified in config/unicorn.rb, config/environments/*.rb, or elsewhere, as well as a matching "path" item in config/gitlab.yml.

    By Administrator on 2012-12-07T00:40:01 (imported from GitLab project)

    By Administrator on 2012-12-07T00:40:01 (imported from GitLab)

  • Created by: riyad

    Rails has an option called config.action_controller.relative_url_root. If I'm correct it will automatically set to whatever is ENV['RAILS_RELATIVE_URL_ROOT'] (see http://edgeguides.rubyonrails.org/configuring.html#configuring-action-controller). So I assume assets and urls in mails will be ok. @frohoff Am I right?

    @frohoff I think what you call "path" should be called "relative_url_root" (the Redmine guys do so too ;) see http://www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_in_a_sub-URI)

    By Administrator on 2012-12-07T19:01:25 (imported from GitLab project)

    By Administrator on 2012-12-07T19:01:25 (imported from GitLab)

  • Created by: frohoff

    @Riyad

    Yes, it seems that ENV['RAILS_RELATIVE_URL_ROOT'] is required for rails to correctly generate "relative-rooted" link/asset urls, and the config.ru change is required to get the actual incoming "relative-rooted" requests to get routed to the right place and get served (404 otherwise); I tried each of these in isolation and couldn't get everything to work without both being present.

    As far as I can tell, all urls in emails and to assets (after a bundle exec rake assets:clean) seem to work properly in our gitlab instance.

    I agree about the configuration naming suggestion and have updated the pull request with those changes. Thanks for the feedback.

    By Administrator on 2012-12-08T00:23:43 (imported from GitLab project)

    By Administrator on 2012-12-08T00:23:43 (imported from GitLab)

  • Created by: ghost

    gitlab v4.0 nginx location /gitlab everything works fine, but gonna test is more tightly

    By Administrator on 2012-12-28T07:18:18 (imported from GitLab project)

    By Administrator on 2012-12-28T07:18:18 (imported from GitLab)

  • Created by: frohoff

    Fixed grack issue and rebased against latest master.

    By Administrator on 2012-12-28T18:14:36 (imported from GitLab project)

    By Administrator on 2012-12-28T18:14:36 (imported from GitLab)

  • Created by: riyad

    :thumbsup:

    By Administrator on 2012-12-28T22:42:16 (imported from GitLab project)

    By Administrator on 2012-12-28T22:42:16 (imported from GitLab)

  • Created by: frohoff

    Tests failing on travis-ci because of ruby-1.9.3-p362 interpreter segfault at active_record/relation.rb:241 (most if not all gitlab builds seem to be failing in the same way). I was able to get them to all pass on my local environment by downgrading to ruby-1.9.3-p194.

    By Administrator on 2012-12-29T17:58:25 (imported from GitLab project)

    By Administrator on 2012-12-29T17:58:25 (imported from GitLab)

  • Created by: SaitoWu

    It just works! :thumbsup:

    Awesome! Thank you.

    By Administrator on 2012-12-29T20:19:59 (imported from GitLab project)

    By Administrator on 2012-12-29T20:19:59 (imported from GitLab)

  • Created by: riyad

    cool :)

    By Administrator on 2012-12-29T22:14:25 (imported from GitLab project)

    By Administrator on 2012-12-29T22:14:25 (imported from GitLab)

  • Created by: misilot

    I am trying this on 4.0, however now when I start /etc/init.d/gitlab unicorn fails to start now.

    I, [2013-01-18T11:43:00.976639 #18486]  INFO -- : Refreshing Gem list
    /usr/local/lib/ruby/1.9.1/psych.rb:154:in `parse': (<unknown>): couldn't parse YAML at line 22 column 19 (Psych::SyntaxError)
            from /usr/local/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
            from /usr/local/lib/ruby/1.9.1/psych.rb:125:in `parse'
            from /usr/local/lib/ruby/1.9.1/psych.rb:112:in `load'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:113:in `initialize'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:71:in `new'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:71:in `instance'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:48:in `[]'
            from /home/gitlab/gitlab/config/initializers/1_settings.rb:309:in `<top (required)>'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:587:in `each'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:587:in `block in <class:Engine>'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
            from /home/gitlab/gitlab/config/environment.rb:5:in `<top (required)>'
            from config.ru:4:in `require'
            from config.ru:4:in `block in <main>'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/rack-1.4.3/lib/rack/builder.rb:51:in `instance_eval'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/rack-1.4.3/lib/rack/builder.rb:51:in `initialize'
            from config.ru:1:in `new'
            from config.ru:1:in `<main>'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn.rb:44:in `eval'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn.rb:44:in `block in builder'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/bin/unicorn_rails:139:in `call'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/bin/unicorn_rails:139:in `block in rails_builder'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:700:in `call'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:700:in `build_app!'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:139:in `start'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/bin/unicorn_rails:209:in `<top (required)>'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/bin/unicorn_rails:23:in `load'
            from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/bin/unicorn_rails:23:in `<main>'
    

    By Administrator on 2013-01-18T17:35:27 (imported from GitLab project)

    By Administrator on 2013-01-18T17:35:27 (imported from GitLab)

  • Created by: ghost

    @misilot can u show your gitlab.yml?

    By Administrator on 2013-01-18T16:48:16 (imported from GitLab project)

    By Administrator on 2013-01-18T16:48:16 (imported from GitLab)

  • Created by: misilot

    # # # # # # # # # # # # # # # # # # 
    # Gitlab application config file  #
    # # # # # # # # # # # # # # # # # #
    #
    # How to use:
    # 1. copy file as gitlab.yml
    # 2. Replace gitlab -> host with your domain
    # 3. Replace gitolite -> ssh_host with your domain
    # 4. Replace gitlab -> email_from
    
    #
    # 1. GitLab app settings
    # ==========================
    
    ## GitLab settings
    gitlab:
      ## Web server settings
      host: servername
      port: 80
      https: true
      relative_url_root: /gitlab
    
      ## Email settings
      # Email address used in the "From" field in mails sent by GitLab
      email_from: gitlab@server
    
      ## Project settings
      default_projects_limit: 10
    
    ## Gravatar
    gravatar:
      enabled: true                 # Use user avatar images from Gravatar.com (default: true)
      # plain_url: "http://..."     # default: http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm
      # ssl_url:   "https://..."    # default: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm
    
    
    
    #
    # 2. Auth settings
    # ==========================
    
    ## LDAP settings
    ldap:
      enabled: false
      host: '_your_ldap_server'
      base: '_the_base_where_you_search_for_users'
      port: 636
      uid: 'sAMAccountName'
      method: 'ssl' # "ssl" or "plain"
      bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
      password: '_the_password_of_the_bind_user'
    
    ## Omniauth settings
    omniauth:
      # Enable ability for users
      # Allow logging in via Twitter, Google, etc. using Omniauth providers
      enabled: false
    
      # CAUTION!
      # This allows users to login without having a user account first (default: false)
      # User accounts will be created automatically when authentication was successful.
      allow_single_sign_on: false
      # Locks down those users until they have been cleared by the admin (default: true)
      block_auto_created_users: true
    
      ## Auth providers
      # Uncomment the lines and fill in the data of the auth provider you want to use
      # If your favorite auth provider is not listed you can user others:
      # see https://github.com/gitlabhq/gitlabhq/wiki/Using-Custom-Omniauth-Providers
      providers:
        # - { name: 'google_oauth2', app_id: 'YOUR APP ID',
        #     app_secret: 'YOUR APP SECRET',
        #     args: { access_type: 'offline', approval_prompt: '' } }
        # - { name: 'twitter', app_id: 'YOUR APP ID',
        #     app_secret: 'YOUR APP SECRET'}
        # - { name: 'github', app_id: 'YOUR APP ID',
        #     app_secret: 'YOUR APP SECRET' }
    
    
    
    #
    # 3. Advanced settings
    # ==========================
    
    ## Backup settings
    backup:
      path: "tmp/backups"   # Relative paths are relative to Rails.root (default: tmp/backups/)
      # keep_time: 604800   # default: 0 (forever) (in seconds)
    
    ## Gitolite settings
    gitolite:
      admin_uri: git@localhost:gitolite-admin
      # repos_path must not be a symlink
      repos_path: /home/git/repositories/
      hooks_path: /home/git/.gitolite/hooks/
      admin_key: gitlab
      upload_pack: true
      receive_pack: true
      ssh_user: git
      ssh_host: localhost
      # ssh_port: 22
      # config_file: gitolite.conf
    
    ## Git settings
    # CAUTION!
    # Use the default values unless you really know what you are doing
    git:
      bin_path: /usr/bin/git
      # Max size of git object like commit, in bytes
      # This value can be increased if you have a very large commits
      max_size: 5242880 # 5.megabytes
      # Git timeout to read commit, in seconds
      timeout: 10
    

    By Administrator on 2013-01-18T17:35:16 (imported from GitLab project)

    By Administrator on 2013-01-18T17:35:16 (imported from GitLab)

  • Created by: frohoff

    You'll probably want to use a "fenced code block" to preserve the white-space. http://github.github.com/github-flavored-markdown/

    By Administrator on 2013-01-18T17:20:37 (imported from GitLab project)

    By Administrator on 2013-01-18T17:20:37 (imported from GitLab)

  • Created by: frohoff

    Also, note that a recent commit in grack_auth.rb broke grack-based smart-http transport when running with a RAILS_RELATIVE_URL_ROOT, though I have a fix in a pending pull request #2623

    By Administrator on 2013-01-18T17:24:07 (imported from GitLab project)

    By Administrator on 2013-01-18T17:24:07 (imported from GitLab)

  • Created by: misilot

    @frohoff the pull request #2623 is already included in this request, it is the last change lasted for this one.

    By Administrator on 2013-01-18T22:23:42 (imported from GitLab project)

    By Administrator on 2013-01-18T22:23:42 (imported from GitLab)

  • Created by: misilot

    By skipping editing the last file: https://github.com/gitlabhq/gitlabhq/pull/2162/files#L6L20 I was able to get it running. Still having a problem with some of the icons though.

    By Administrator on 2013-01-18T22:39:49 (imported from GitLab project)

    By Administrator on 2013-01-18T22:39:49 (imported from GitLab)

  • Created by: frohoff

    If you were running at / before you'll probably need to do a bundle exec rake assets:clean to force the sass resources to be regenerated with the new correct path prefix in embedded URLs.

    By Administrator on 2013-01-18T22:52:10 (imported from GitLab project)

    By Administrator on 2013-01-18T22:52:10 (imported from GitLab)

  • Created by: frohoff

    The grack_auth.rb file you mentioned should have nothing to do with gitlab.yml parsing or static assets. I only mentioned it in case anyone was counting on using grack/smart-http with RAILS_RELATIVE_URL_ROOT in 4.1.

    By Administrator on 2013-01-18T22:58:31 (imported from GitLab project)

    By Administrator on 2013-01-18T22:58:31 (imported from GitLab)

  • Created by: misilot

    Thanks, that worked!

    By Administrator on 2013-01-18T23:10:54 (imported from GitLab project)

    By Administrator on 2013-01-18T23:10:54 (imported from GitLab)

  • Created by: info-former03

    Remove the lines from grack_auth.rb (#2623), also worked for me.

    I'm still having the issue, that /tree/master & /commits/master leads to 404-Error for any project. Without RELATIVE_ROOT in gitlab.yml and unicorn config it works fine. Can you take a look at it?

    Thanks

    By Administrator on 2013-01-22T19:45:15 (imported from GitLab project)

    By Administrator on 2013-01-22T19:45:15 (imported from GitLab)

  • gitlab-qa-bot
45 46 Settings.gitlab['host'] ||= 'localhost'
46 47 Settings.gitlab['https'] ||= false
47 48 Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
49 Settings.gitlab['relative_url_root'] ||= ''
  • Created by: mikew

    I've found using

    Settings.gitlab['relative_url_root'] ||= ENV['RAILS_RELATIVE_URL_ROOT'] || ''

    is more flexible. one can set it an env file, directly in the Procfile, in config/unicorn.rb, in /etc/init.d/gitlab and not need to bother with the setting in config/gitlab.yml. DRY and such.

    By Administrator on 2013-01-31T20:11:40 (imported from GitLab project)

    By Administrator on 2013-01-31T20:11:40 (imported from GitLab)

  • gitlab-qa-bot
  • 45 46 Settings.gitlab['host'] ||= 'localhost'
    46 47 Settings.gitlab['https'] ||= false
    47 48 Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
    49 Settings.gitlab['relative_url_root'] ||= ''
    • Created by: frohoff

      @mikew I've been wondering if it could be more DRY. Do email notifications get URLs built with the proper path prefix in that configuration?

      By Administrator on 2013-01-31T20:41:00 (imported from GitLab project)

      By Administrator on 2013-01-31T20:41:00 (imported from GitLab)

  • gitlab-qa-bot
  • 45 46 Settings.gitlab['host'] ||= 'localhost'
    46 47 Settings.gitlab['https'] ||= false
    47 48 Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
    49 Settings.gitlab['relative_url_root'] ||= ''
    • Created by: mikew

      Ah, haven't gotten an email from my gitlab install in a while. not even sure if it is configured properly. what's the quickest way to get gitlab to send an email? though an actual spec would be best, of course.

      By Administrator on 2013-01-31T20:51:51 (imported from GitLab project)

      By Administrator on 2013-01-31T20:51:51 (imported from GitLab)

  • gitlab-qa-bot
  • 45 46 Settings.gitlab['host'] ||= 'localhost'
    46 47 Settings.gitlab['https'] ||= false
    47 48 Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
    49 Settings.gitlab['relative_url_root'] ||= ''
    • Created by: mikew

      ah, "forgot password" mail couldn't send, but reading it via postcat -q I can see the proper RAILS_RELATIVE_URL_ROOT is there.

      By Administrator on 2013-01-31T21:03:32 (imported from GitLab project)

      By Administrator on 2013-01-31T21:03:32 (imported from GitLab)

  • gitlab-qa-bot
  • 45 46 Settings.gitlab['host'] ||= 'localhost'
    46 47 Settings.gitlab['https'] ||= false
    47 48 Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
    49 Settings.gitlab['relative_url_root'] ||= ''
    • Created by: frohoff

      Nice. I'll give that a test when I get a chance. You going to submit a pull request or should I?

      By Administrator on 2013-01-31T21:32:57 (imported from GitLab project)

      By Administrator on 2013-01-31T21:32:57 (imported from GitLab)

  • gitlab-qa-bot
  • 45 46 Settings.gitlab['host'] ||= 'localhost'
    46 47 Settings.gitlab['https'] ||= false
    47 48 Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
    49 Settings.gitlab['relative_url_root'] ||= ''
    • Created by: mikew

      in the process now. just a minute.

      By Administrator on 2013-01-31T21:50:17 (imported from GitLab project)

      By Administrator on 2013-01-31T21:50:17 (imported from GitLab)

  • Created by: ace-han

    Hi, There

    I've found the comment in the gitlab.yml and followed the instruction to finished the modification.

        # Uncomment and customize the last line to run in a non-root path
        # WARNING: We recommend creating a FQDN to host GitLab in a root path instead of this.
        # Note that four settings need to be changed for this to work.
        # 1) In your application.rb file: config.relative_url_root = "/gitlab"
        # 2) In your gitlab.yml file: relative_url_root: /gitlab
        # 3) In your unicorn.rb: ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab"
        # 4) In ../gitlab-shell/config.yml: gitlab_url: "http://127.0.0.1/gitlab"
        # To update the path, run: sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
        #
        # relative_url_root: /gitlab

    However, I could not find any wiki or doc about the corresponding nginx config. Can anyone provide a working subdir url config in nginx about gitlab, so that other people could visit it by http://${YOURDOMAIN}/gitlab.

    Many thanks

    P.S.: I'm using branch 6-4-stable

    By Administrator on 2014-01-19T13:11:53 (imported from GitLab project)

    By Administrator on 2014-01-19T13:11:53 (imported from GitLab)

  • Created by: MerryLad

    After upgrading to 4.2, I've experienced regressions in this regard.

    I've deleted all files in the assets folder, and regenerated.

    sudo -u git -H bundle exec rake cache:clear RAILS_ENV=production RAILS_RELATIVE_URL_ROOT=/gitlab

    I have also changed the path on gitlab.yml and unicorn.rb

    Most files do load from /gitlab/assets, with the notable exception of fontawesome, which gets loaded from domain.com/assets

    Application works just fine, it's just the users will see garbled icons.

    Any tips on this?

    By Administrator on 2014-01-19T22:21:13 (imported from GitLab project)

    By Administrator on 2014-01-19T22:21:13 (imported from GitLab)

  • Created by: ace-han

    OKay, I've found a working instruction from stackoverflow not only answering apache settings but also nginx's settings

    http://stackoverflow.com/questions/17924644/gitlab-in-a-subdirectory-with-apache-and-passenger

    Updated: http://stackoverflow.com/questions/13232528/how-to-configure-nginx-to-serve-gitlabhq-on-a-suburi/21248435#answer-21248435

    By Administrator on 2014-01-22T16:59:10 (imported from GitLab project)

    By Administrator on 2014-01-22T16:59:10 (imported from GitLab)

  • Created by: nikolauskrismer

    I am not sure why this problem only affects the fontawesome files (like MerryLad commented and which is also true for me) For me this problem only occurs after upgrading to latest gitlab v 6.5 (using the update script). I had no problems with version 6.4 (which I updated from 6.3 by hand...)

    However, I "solved" it by adding a second proxy line in my apache configuration (I do use an apache proxy for gitlab) as suggested by user1258056 in stackoverflow (more information about this can be found using the link ace-han posted)

    By Administrator on 2014-01-22T16:44:24 (imported from GitLab project)

    By Administrator on 2014-01-22T16:44:24 (imported from GitLab)

  • Created by: edeca

    I'm seeing the same problem as MerryLad mentions above with icons and FontAwesome.

    By Administrator on 2014-06-12T14:02:53 (imported from GitLab project)

    By Administrator on 2014-06-12T14:02:53 (imported from GitLab)

  • Please register or sign in to reply
    Loading