Forwarding to GitLab Subdomain with Existing Nginx Installation

前端 未结 6 1736
日久生厌
日久生厌 2020-12-29 14:53

I\'ve been following the instructions from the GitLab wiki, however, it seems as if some key pieces of information are missing. In the section \"Using a Non-Bundled Web Serv

6条回答
  •  情话喂你
    2020-12-29 14:58

    It took me a couple of days to get everything sorted out, so I wanted to share the steps it took to get it all working. This is how to install Nginx for a website and get it working with an existing gitlab repo (that uses a bundled version of Nginx). MY gitlab repo is on a subdomain of my website called 'repos'.

    Open a terminal and install Nginx:

    sudo apt-get update
    sudo apt-get install nginx
    

    Edit configuration file /etc/nginx/nginx.conf:

    Find your user name, which you will need when configuring gitlab: In my case this was 'nginx':

    user   nginx;
    

    Add this line inside the http{ } block :

    $include /etc/nginx/sites-enabled/*;
    

    Example:

    http{
        include  etc/nginx/mime.types;
        include  etc/nginx/sites-enabled/*;
    
        (more stuff...)
    }
    

    Edit configuration file /etc/gitlab/gitlab.rb:

    Change this line:

    external_url 'GENERATED_EXTERNAL_URL' 
    

    To:

    external_url 'http://www.example.com/repos'  // (whatever your server name is)  
    

    Uncomment and change this line:

    nginx['enable'] = true
    

    To:

    nginx['enable'] = false
    

    Uncomment and change this line:

    web_server['external_users'] = []    
    

    To:

    web_server['external_users'] = ['nginx']     // or whatever your nginx user is called, sometimes it's 'www-data'
    

    Nginx needs a configuration file for gitlab:

    On the GitLab recipes repository: https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server/nginx find 'gitlab-omnibus-nginx.conf'. Put that file in the folder /etc/nginx/sites-enabled (you may need to create the sites-enabled folder)

    Edit configuration file /etc/nginx/sites-enabled/gitlab-omnibus-nginx.conf:

    Change this line:

    server_name YOUR_SERVER_FQDN
    

    To:

    server_name www.example.com/repos     // (or whatever your server name is)
    

    You will need to change the port that gitlab is on so that the website and git server both work.

    Change this line:

    listen 0.0.0.0:80 default_server;
    

    To:

    listen 0.0.0.0:8081; 
    

    Change this line:

    listen [::]:80  default_server;
    

    To:

    listen [::]:8081;
    

    Edit configuration file /etc/nginx/conf.d/default.conf:

    Make this the default server:

    listen    80 default_server;
    server_name  localhost;
    

    Add a second location for the gitlab repo and use proxy_pass to point to the port you put Gitlab on. I put my Gitlab in the sub-directory 'repos'. The number 127.0.0.1 means localhost (the same computer):

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    location /repos/ {
        proxy_pass http://127.0.0.1:8081;
    }
    

    Run these commands in the terminal:

    sudo gitlab-ctl reconfigure
    sudo service nginx restart
    

    Your webserver and gitlab should now both be working and accessible online. Nginx will default to /usr/share/nginx/html when a user visits your webserver. There is a default .html file there. That is where you can put files for your website.

提交回复
热议问题