Skip to content

Commit 7cf0fa2

Browse files
committed
Update nginx config to use strong ssl security
https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
1 parent cf9c977 commit 7cf0fa2

File tree

1 file changed

+139
-69
lines changed

1 file changed

+139
-69
lines changed

web-server/nginx/gitlab-ssl

Lines changed: 139 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
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+
## cd /etc/nginx/
22+
## sudo openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
23+
## sudo chmod o-r gitlab.key
24+
##
25+
## Edit `gitlab-shell/config.yml`:
26+
## 1) Set "gitlab_url" param in `gitlab-shell/config.yml` to `https://git.example.com`
27+
## 2) Set "ca_file" to `/etc/nginx/gitlab.crt`
28+
## 3) Set "self_signed_cert" to `true`
29+
## Edit `gitlab/config/gitlab.yml`:
30+
## 1) Define port for http "port: 443"
31+
## 2) Enable https "https: true"
32+
## 3) Update ssl for gravatar "ssl_url: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm"
33+
##
34+
##################################
35+
## CHUNKED TRANSFER ##
36+
##################################
37+
##
38+
## It is a known issue that Git-over-HTTP requires chunked transfer encoding [0]
39+
## which is not supported by Nginx < 1.3.9 [1]. As a result, pushing a large object
40+
## with Git (i.e. a single large file) can lead to a 411 error. In theory you can get
41+
## around this by tweaking this configuration file and either:
42+
## - installing an old version of Nginx with the chunkin module [2] compiled in, or
43+
## - using a newer version of Nginx.
44+
##
45+
## At the time of writing we do not know if either of these theoretical solutions works. As a workaround
46+
## users can use Git over SSH to push large files.
47+
##
48+
## [0] https://git.kernel.org/cgit/git/git.git/tree/Documentation/technical/http-protocol.txt#n99
49+
## [1] https://github.com/agentzh/chunkin-nginx-module#status
50+
## [2] https://github.com/agentzh/chunkin-nginx-module
51+
2052

2153
upstream gitlab {
2254

@@ -25,60 +57,98 @@ upstream gitlab {
2557

2658
## Uncomment if puma/unicorn are configured to listen on a tcp port.
2759
## Check the port number in /home/git/gitlab/config/{puma.rb/unicorn.rb}
28-
# server 127.0.0.1:9292;
60+
# server 127.0.0.1:8080;
2961
}
3062

31-
# This is a normal HTTP host which redirects all traffic to the HTTPS host.
32-
# Replace git.example.com with your FQDN.
63+
## This is a normal HTTP host which redirects all traffic to the HTTPS host.
3364
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;
65+
listen *:80;
66+
## Replace git.example.com with your FQDN.
67+
server_name git.example.com;
68+
server_tokens off;
69+
## this doesn't have to be a valid path since we are redirecting, you don't have to change it.
70+
root /nowhere;
71+
rewrite ^ https://$server_name$request_uri permanent;
3972
}
73+
4074
server {
41-
listen 443 ssl;
42-
server_name git.example.com;
43-
server_tokens off;
75+
listen 443 ssl;
76+
server_name git.example.com; # Replace git.example.com with your FQDN.
77+
server_tokens off;
78+
root /home/git/gitlab/public;
79+
80+
## Increase this if you want to upload large attachments
81+
## Or if you want to accept large git objects over http
82+
client_max_body_size 20m;
83+
84+
## Strong SSL Security
85+
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
86+
ssl on;
87+
ssl_certificate /etc/nginx/gitlab.crt;
88+
ssl_certificate_key /etc/nginx/gitlab.key;
89+
90+
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';
91+
92+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
93+
ssl_session_cache builtin:1000 shared:SSL:10m;
94+
95+
ssl_stapling on;
96+
ssl_stapling_verify on;
97+
resolver 8.8.4.4 8.8.8.8 valid=300s;
98+
resolver_timeout 10s;
99+
100+
ssl_prefer_server_ciphers on;
101+
## [Optional] Generate a stronger DHE parameter (recommended):
102+
## cd /etc/ssl/certs
103+
## openssl dhparam -out dhparam.pem 2048
104+
##
105+
# ssl_dhparam /etc/ssl/certs/dhparam.pem;
106+
107+
add_header Strict-Transport-Security max-age=63072000;
108+
add_header X-Frame-Options DENY;
109+
add_header X-Content-Type-Options nosniff;
110+
111+
## Individual nginx logs for this GitLab vhost
112+
access_log /var/log/nginx/gitlab_access.log;
113+
error_log /var/log/nginx/gitlab_error.log;
114+
115+
location / {
116+
## Serve static files from defined root folder.
117+
## @gitlab is a named location for the upstream fallback, see below.
118+
try_files $uri $uri/index.html $uri.html @gitlab;
119+
}
120+
121+
## If a file, which is not found in the root folder is requested,
122+
## then the proxy pass the request to the upsteam (gitlab unicorn).
123+
location @gitlab {
124+
125+
## If you use https make sure you disable gzip compression
126+
## to be safe against BREACH attack.
127+
gzip off;
128+
129+
## https://github.com/gitlabhq/gitlabhq/issues/694
130+
## Some requests take more than 30 seconds.
131+
proxy_read_timeout 300;
132+
proxy_connect_timeout 300;
133+
proxy_redirect off;
134+
135+
proxy_set_header Host $http_host;
136+
proxy_set_header X-Real-IP $remote_addr;
137+
proxy_set_header X-Forwarded-Ssl on;
138+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
139+
proxy_set_header X-Forwarded-Proto $scheme;
140+
141+
proxy_pass http://gitlab;
142+
}
143+
144+
## Enable gzip compression as per rails guide:
145+
## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
146+
location ~ ^/(assets)/ {
44147
root /home/git/gitlab/public;
148+
gzip_static on; # to serve pre-gzipped version
149+
expires max;
150+
add_header Cache-Control public;
151+
}
45152

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-
}
153+
error_page 502 /502.html;
154+
}

0 commit comments

Comments
 (0)