Skip to content

Commit 85c7552

Browse files
committed
Merge branch 'nginx_ssl_update' into 'master'
Add nginx strong ssl security
2 parents cf9c977 + 57fb4d4 commit 85c7552

File tree

1 file changed

+147
-69
lines changed

1 file changed

+147
-69
lines changed

web-server/nginx/gitlab-ssl

Lines changed: 147 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,55 @@
1-
# GITLAB
2-
# Contributors: yin8086, sashkab, orkoden, axilleas
3-
# App Version: 5.4 - 6.0
4-
5-
# Modified from nginx http version
6-
# Modified from http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/
7-
8-
# You need to run openssl to generate a self-signed ssl certificate.
9-
# cd /etc/nginx/
10-
# sudo openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
11-
# sudo chmod o-r gitlab.key
12-
# Also you need to edit gitlab-shell config.
13-
# 1) Set "gitlab_url" param in gitlab-shell/config.yml to https://git.example.com
14-
# 2) Set "ca_file" to /etc/nginx/gitlab.crt
15-
# 3) Set "self_signed_cert" to true
16-
# You also need to edit gitlab/config/gitlab.yml
17-
# 1) Define port for http "port: 443"
18-
# 2) Enable https "https: true"
19-
# 3) Update ssl for gravatar "ssl_url: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm"
1+
## GitLab
2+
## Contributors: randx, yin8086, sashkab, orkoden, axilleas
3+
## App Version: 5.4 - 6.0
4+
##
5+
## Modified from nginx http version
6+
## Modified from http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/
7+
##
8+
## Lines starting with two hashes (##) are comments containing information
9+
## for configuration. One hash (#) comments are actual configuration parameters
10+
## which you can comment/uncomment to your liking.
11+
##
12+
###################################
13+
## SSL configuration ##
14+
###################################
15+
##
16+
## Optimal configuration is taken from:
17+
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
18+
## Make sure to read it and understand what each option does.
19+
##
20+
## [Optional] Generate a self-signed ssl certificate:
21+
## mkdir /etc/nginx/ssl/
22+
## cd /etc/nginx/ssl/
23+
## sudo openssl req -new rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
24+
## sudo chmod o-r gitlab.key
25+
##
26+
## Edit `gitlab-shell/config.yml`:
27+
## 1) Set "gitlab_url" param in `gitlab-shell/config.yml` to `https://git.example.com`
28+
## 2) Set "ca_file" to `/etc/nginx/gitlab.crt`
29+
## 3) Set "self_signed_cert" to `true`
30+
## Edit `gitlab/config/gitlab.yml`:
31+
## 1) Define port for http "port: 443"
32+
## 2) Enable https "https: true"
33+
## 3) Update ssl for gravatar "ssl_url: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm"
34+
##
35+
##################################
36+
## CHUNKED TRANSFER ##
37+
##################################
38+
##
39+
## It is a known issue that Git-over-HTTP requires chunked transfer encoding [0]
40+
## which is not supported by Nginx < 1.3.9 [1]. As a result, pushing a large object
41+
## with Git (i.e. a single large file) can lead to a 411 error. In theory you can get
42+
## around this by tweaking this configuration file and either:
43+
## - installing an old version of Nginx with the chunkin module [2] compiled in, or
44+
## - using a newer version of Nginx.
45+
##
46+
## At the time of writing we do not know if either of these theoretical solutions works. As a workaround
47+
## users can use Git over SSH to push large files.
48+
##
49+
## [0] https://git.kernel.org/cgit/git/git.git/tree/Documentation/technical/http-protocol.txt#n99
50+
## [1] https://github.com/agentzh/chunkin-nginx-module#status
51+
## [2] https://github.com/agentzh/chunkin-nginx-module
52+
2053

2154
upstream gitlab {
2255

@@ -25,60 +58,105 @@ upstream gitlab {
2558

2659
## Uncomment if puma/unicorn are configured to listen on a tcp port.
2760
## Check the port number in /home/git/gitlab/config/{puma.rb/unicorn.rb}
28-
# server 127.0.0.1:9292;
61+
# server 127.0.0.1:8080;
2962
}
3063

31-
# This is a normal HTTP host which redirects all traffic to the HTTPS host.
32-
# Replace git.example.com with your FQDN.
64+
## This is a normal HTTP host which redirects all traffic to the HTTPS host.
3365
server {
34-
listen *:80;
35-
server_name git.example.com;
36-
server_tokens off;
37-
root /nowhere; # this doesn't have to be a valid path since we are redirecting, you don't have to change it.
38-
rewrite ^ https://$server_name$request_uri permanent;
66+
listen *:80;
67+
## Replace git.example.com with your FQDN.
68+
server_name git.example.com;
69+
server_tokens off;
70+
## This doesn't have to be a valid path since we are redirecting,
71+
## you don't have to change it.
72+
root /nowhere;
73+
rewrite ^ https://$server_name$request_uri permanent;
3974
}
75+
4076
server {
41-
listen 443 ssl;
42-
server_name git.example.com;
43-
server_tokens off;
77+
listen 443 ssl;
78+
## Replace git.example.com with your FQDN.
79+
server_name git.example.com;
80+
server_tokens off;
81+
root /home/git/gitlab/public;
82+
83+
## Increase this if you want to upload large attachments
84+
## Or if you want to accept large git objects over http
85+
client_max_body_size 20m;
86+
87+
## Strong SSL Security
88+
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
89+
ssl on;
90+
ssl_certificate /etc/nginx/ssl/gitlab.crt;
91+
ssl_certificate_key /etc/nginx/ssl/gitlab.key;
92+
93+
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';
94+
95+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
96+
ssl_session_cache builtin:1000 shared:SSL:10m;
97+
98+
## Enable OCSP stapling to reduce the overhead and latency of running SSL.
99+
## Replace with your ssl_trusted_certificate. For more info see:
100+
## - https://medium.com/devops-programming/4445f4862461
101+
## - https://www.ruby-forum.com/topic/4419319
102+
ssl_stapling on;
103+
ssl_stapling_verify on;
104+
ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt;
105+
resolver 208.67.222.222 208.67.222.220 valid=300s;
106+
resolver_timeout 10s;
107+
108+
ssl_prefer_server_ciphers on;
109+
## [Optional] Generate a stronger DHE parameter (recommended):
110+
## cd /etc/ssl/certs
111+
## openssl dhparam -out dhparam.pem 2048
112+
##
113+
# ssl_dhparam /etc/ssl/certs/dhparam.pem;
114+
115+
add_header Strict-Transport-Security max-age=63072000;
116+
add_header X-Frame-Options DENY;
117+
add_header X-Content-Type-Options nosniff;
118+
119+
## Individual nginx logs for this GitLab vhost
120+
access_log /var/log/nginx/gitlab_access.log;
121+
error_log /var/log/nginx/gitlab_error.log;
122+
123+
location / {
124+
## Serve static files from defined root folder.
125+
## @gitlab is a named location for the upstream fallback, see below.
126+
try_files $uri $uri/index.html $uri.html @gitlab;
127+
}
128+
129+
## If a file, which is not found in the root folder is requested,
130+
## then the proxy pass the request to the upsteam (gitlab unicorn).
131+
location @gitlab {
132+
133+
## If you use https make sure you disable gzip compression
134+
## to be safe against BREACH attack.
135+
gzip off;
136+
137+
## https://github.com/gitlabhq/gitlabhq/issues/694
138+
## Some requests take more than 30 seconds.
139+
proxy_read_timeout 300;
140+
proxy_connect_timeout 300;
141+
proxy_redirect off;
142+
143+
proxy_set_header Host $http_host;
144+
proxy_set_header X-Real-IP $remote_addr;
145+
proxy_set_header X-Forwarded-Ssl on;
146+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
147+
proxy_set_header X-Forwarded-Proto $scheme;
148+
149+
proxy_pass http://gitlab;
150+
}
151+
152+
## Enable gzip compression as per rails guide:
153+
## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
154+
location ~ ^/(assets)/ {
44155
root /home/git/gitlab/public;
156+
gzip_static on; # to serve pre-gzipped version
157+
expires max;
158+
add_header Cache-Control public;
159+
}
45160

46-
# Increase this if you want to upload large attachments
47-
# Or if you want to accept large git objects over http
48-
client_max_body_size 20m;
49-
50-
ssl on;
51-
ssl_certificate /etc/nginx/gitlab.crt;
52-
ssl_certificate_key /etc/nginx/gitlab.key;
53-
ssl_protocols SSLv3 TLSv1 TLSv1.2;
54-
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';
55-
ssl_prefer_server_ciphers on;
56-
57-
# individual nginx logs for this gitlab vhost
58-
access_log /var/log/nginx/gitlab_access.log;
59-
error_log /var/log/nginx/gitlab_error.log;
60-
61-
location / {
62-
# serve static files from defined root folder;.
63-
# @gitlab is a named location for the upstream fallback, see below
64-
try_files $uri $uri/index.html $uri.html @gitlab;
65-
}
66-
67-
# if a file, which is not found in the root folder is requested,
68-
# then the proxy pass the request to the upsteam (gitlab unicorn)
69-
location @gitlab {
70-
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
71-
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
72-
proxy_redirect off;
73-
74-
proxy_set_header Host $http_host;
75-
proxy_set_header X-Real-IP $remote_addr;
76-
proxy_set_header X-Forwarded-Ssl on;
77-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
78-
proxy_set_header X-Forwarded-Proto $scheme;
79-
80-
proxy_pass http://gitlab;
81-
}
82-
83-
error_page 502 /502.html;
84-
}
161+
error_page 502 /502.html;
162+
}

0 commit comments

Comments
 (0)