Gitlab如何使用默认的nginx

Gitlab安装的OM版,默认会安装nginx,并在 gitlab-ctl start 中会默认启动 nginx。但如果想用自带的nginx设置,可以参考本文进行设置。

Gitlab默认安装的nginx的目录

/var/opt/gitlab/nginx

Tips 1:在/var/opt/gitlab目录下,除了nginx 还有其它一些依赖服务。

Tips 2:unicorn是ruby的http server,nginx只是反向代理。这个是灵魂,把握了这个原则更改成自带的nginx就手到擒来了。

本人自带的nginx的配置目录 /etc/nginx/sites.d

# cp /var/opt/gitlab/nginx/conf/gitlab-http.conf /etc/nginx/sites.d/gitlab-http.conf
# cp /var/opt/gitlab/nginx/conf/nginx-status.conf /etc/nginx/sites.d/gitlab-nginx-status.conf

修改代码:

vim /etc/nginx/nginx.conf
user  git; //将nginx的运行用户更改为git,主要是为了能够和
/var/opt/gitlab/gitlab-workhorse/socket通信。

vim /etc/nginx/sites.d/gitlab-http.conf ,头部增加如下代码:

upstream gitlab-workhorse {
  server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
proxy_cache_path proxy_cache keys_zone=gitlab:10m max_size=1g levels=1:2;
proxy_cache gitlab;
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

贴上本人的配置:

pstream gitlab-workhorse {
server unix:/var/opt/gitlab/gitlab-workhorse/socket;
#server 192.168.80.122:8080;
}

proxy_cache_path proxy_cache keys_zone=gitlab:10m max_size=1g levels=1:2;
proxy_cache gitlab;

map $http_upgrade $connection_upgrade {
default upgrade;
”      close;
}

server {
listen 80;

server_name 122.100.com;
server_tokens off; ## Don’t show the nginx version number, a security best practice

## Increase this if you want to upload large attachments
## Or if you want to accept large git objects over http
client_max_body_size 0;

add_header Strict-Transport-Security “max-age=31536000″;

access_log  /var/log/nginx/access.log main;
error_log   /var/log/nginx/error.log;

if ($http_host = “”) {
set $http_host_with_default “122.100.com”;
}

if ($http_host != “”) {
set $http_host_with_default $http_host;
}

## If you use HTTPS make sure you disable gzip compression
## to be safe against BREACH attack.
## https://github.com/gitlabhq/gitlabhq/issues/694
## Some requests take more than 30 seconds.
proxy_read_timeout      3600;
proxy_connect_timeout   300;
proxy_redirect          off;
proxy_http_version 1.1;

proxy_set_header Host $http_host_with_default;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto http;

location / {
proxy_cache off;
proxy_pass  http://gitlab-workhorse;
}

location /assets {
proxy_cache gitlab;
proxy_pass  http://gitlab-workhorse;
}

error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 /500.html;
error_page 502 /502.html;
location ~ ^/(404|422|500|502)(-custom)?\.html$ {
root /opt/gitlab/embedded/service/gitlab-rails/public;
internal;
}

}

Gitlab如何使用默认的nginx》上有1条评论

  1. Pingback引用通告: Gitlab中的配置参数 | 精彩每一天

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>