Centos7上Gitlab使用非捆绑Nginx

6 篇文章 0 订阅
5 篇文章 0 订阅

在Gitlab中使用捆绑的nginx非常的难受,毕竟我们的机器上不是只有gitlab这一个服务可能还有其他的站点

那么如何修改呢?

1、首先安装非捆绑nginx的依赖

sudo yum install epel-release

2、安装nginx

sudo yum install nginx

3、禁用的捆绑nginx,可以去到/etc/gitlab/gitlab.rb文件下修改

nginx[‘enable’] = true –> nginx[‘enable’] = false

4、将线上nginx配置拷贝至/etc/nginx/conf.d/gitlab-omnibus-nginx.conf文件,修改代码中YOUR_SERVER_FQDN为你的域名,

## GitLab 8.3+
##
## Lines starting with two hashes (##) are comments with information.
## Lines starting with one hash (#) are configuration parameters that can be uncommented.
##
##################################
##        CONTRIBUTING          ##
##################################
##
## If you change this file in a Merge Request, please also create
## a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
##
###################################
##         configuration         ##
###################################
##
## See installation.md#using-https for additional HTTPS configuration details.

upstream gitlab-workhorse {
  # On GitLab versions before 13.5, the location is
  # `/var/opt/gitlab/gitlab-workhorse/socket`. Change the following line
  # accordingly.
  server unix:/var/opt/gitlab/gitlab-workhorse/sockets/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 [::]:80 default_server;
  server_name YOUR_SERVER_FQDN; ## 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;
  }
}

5、禁用 /etc/nginx/nginx.conf 中的默认的80端口的server配置

38     server {
39         listen       80 default_server;
40         listen       [::]:80 default_server;
41         server_name  _;
42         root         /usr/share/nginx/html;
43
44         # Load configuration files for the default server block.
45         include /etc/nginx/default.d/*.conf;
46
47         location / {
48         }
49
50         error_page 404 /404.html;
51             location = /40x.html {
52         }
53
54         error_page 500 502 503 504 /50x.html;
55             location = /50x.html {
56         }
57     }

这里将这段默认配置注释掉

38  #     server {
39  #         listen       80 default_server;
40  #         listen       [::]:80 default_server;
41  #         server_name  _;
42  #         root         /usr/share/nginx/html;
43  #
44  #         # Load configuration files for the default server block.
45  #         include /etc/nginx/default.d/*.conf;
46  #
47  #         location / {
48  #         }
49  #
50  #         error_page 404 /404.html;
51  #             location = /40x.html {
52  #         }
53  #
54  #         error_page 500 502 503 504 /50x.html;
55  #             location = /50x.html {
56  #         }
57  #     }

6、检查nginx配置是否正确

[root@hellogitlab ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

7、加载gitlab的配置,使用命令

gitlab-ctl reconfigure

8、开启nginx

sudo systemctl start nginx

如果页面访问报502可能是权限问题查看错误日志(路径: /var/log/nginx/gitlab_error.log)做chmod赋权操作即可。

参考:

1、https://meigit.readthedocs.io/en/latest/centos7_install_gitlab_with_external_nginx_and_https.html#webnginx

2、https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值