该配置根据官网提供的配置修改而来: https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/nginx/gitlab-omnibus-nginx.conf。
重启nginx:
$sudo service nginx restart4.登陆浏览器,这时可以看到安装成功了,如下图所示:
首次登陆会要求重置管理员密码,管理员的默认用户名为root。
https的支持1.使用Let's encrypt申请免费的SSL证书,该项目提供了一个叫certbot/certbot-auto的工具获取证书,执行下面命令获取工具:
$wget https://dl.eff.org/certbot-auto $chmod +x certbot-auto执行下面命令生成生成gitlab.papamk.com的证书,其中--agree-tos表示同意协议,--email 95496875@qq.com为自己的email。
$./certbot-auto --agree-tos --email 95496875@qq.com certonly --webroot -w /opt/gitlab/embedded/service/gitlab-rails/public/ -d gitlab.papamk.com执行成功后,可通过以下命令查看下证书位置,nginx需要引用这些文件。(一般位于/etc/letsencrypt/live/gitlab.papamk.com/目录)
$./certbot-auto certificates2.修改/etc/gitlab/gitlab.rb,对外的URL改为https:
external_url 'https://gitlab.papamk.com'执行重新配置命令以便让新配置生效:
$gitlab-ctl reconfigure3.修改前面的nginx的gitlab.conf的配置,全部替换成下面的内容(所有需要注意的地方都加了中文注释):
upstream gitlab-workhorse { server 172.18.147.173:8181; #根据实际情况修改 } ## Redirects all HTTP traffic to the HTTPS 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 () listen 0.0.0.0:80; listen [::]:80 ipv6only=on default_server; server_name gitlab.papamk.com; ## 改成自己的域名 server_tokens off; ## Don't show the nginx version number, a security best practice return 301 https://$http_host$request_uri; access_log /home/wwwlogs/gitlab_access.log; # 根据实际情况修改 error_log /home/wwwlogs/gitlab_error.log; # 根据实际情况修改 } ## HTTPS host server { listen 0.0.0.0:443 ssl; listen [::]:443 ipv6only=on ssl default_server; server_name gitlab.papamk.com; ## 改成自己的域名 server_tokens off; ## Don't show the nginx version number, a security best practice root /opt/gitlab/embedded/service/gitlab-rails/public; ## Strong SSL Security ## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/ ssl on; ssl_certificate /etc/letsencrypt/live/gitlab.papamk.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/gitlab.papamk.com/privkey.pem; # GitLab needs backwards compatible ciphers to retain compatibility with Java IDEs ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 5m; ## sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 4096 # ssl_dhparam /etc/ssl/certs/dhparam.pem; access_log /home/wwwlogs/gitlab_access.log; # 根据实际情况修改 error_log /home/wwwlogs/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-Ssl on; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass ; } }重启nginx:
$sudo service nginx restart4.定期更新ssl证书
Let's encrypt提供的证书,有效期为90天,到期后执行如下命令即可继续使用:
将该命令加入到crontab,每小时刷新一次,就不用担心过期了。先将该命令移到系统目录下:
$sudo mv certbot-auto /usr/bin/certbot-auto然后执行crontab -e,添加一行:
0 */1 * * * /usr/bin/certbot-auto renew 发送邮件的支持