Advertisement
Guest User

Untitled

a guest
Dec 9th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. ## GitLab
  2. ##
  3. ## Modified from nginx http version
  4. ## Modified from http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/
  5. ## Modified from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
  6. ##
  7. ## Lines starting with two hashes (##) are comments with information.
  8. ## Lines starting with one hash (#) are configuration parameters that can be uncommented.
  9. ##
  10. ##################################
  11. ## CONTRIBUTING ##
  12. ##################################
  13. ##
  14. ## If you change this file in a Merge Request, please also create
  15. ## a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
  16. ##
  17. ##################################
  18. ## CHUNKED TRANSFER ##
  19. ##################################
  20. ##
  21. ## It is a known issue that Git-over-HTTP requires chunked transfer encoding [0]
  22. ## which is not supported by Nginx < 1.3.9 [1]. As a result, pushing a large object
  23. ## with Git (i.e. a single large file) can lead to a 411 error. In theory you can get
  24. ## around this by tweaking this configuration file and either:
  25. ## - installing an old version of Nginx with the chunkin module [2] compiled in, or
  26. ## - using a newer version of Nginx.
  27. ##
  28. ## At the time of writing we do not know if either of these theoretical solutions works.
  29. ## As a workaround users can use Git over SSH to push large files.
  30. ##
  31. ## [0] https://git.kernel.org/cgit/git/git.git/tree/Documentation/technical/http-protocol.txt#n99
  32. ## [1] https://github.com/agentzh/chunkin-nginx-module#status
  33. ## [2] https://github.com/agentzh/chunkin-nginx-module
  34. ##
  35. ###################################
  36. ## configuration ##
  37. ###################################
  38. ##
  39. ## See installation.md#using-https for additional HTTPS configuration details.
  40.  
  41. upstream gitlab {
  42. server unix:/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket fail_timeout=0;
  43. }
  44.  
  45. upstream gitlab-workhorse {
  46. server unix:/var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0;
  47. }
  48.  
  49. ## Redirects all HTTP traffic to the HTTPS host
  50. server {
  51. ## Either remove "default_server" from the listen line below,
  52. ## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
  53. ## to be served if you visit any address that your server responds to, eg.
  54. ## the ip address of the server (http://x.x.x.x/)
  55. listen 0.0.0.0:80;
  56. listen [::]:80 ipv6only=on default_server;
  57. server_name HOSTNAME; ## Replace this with something like gitlab.example.com
  58. server_tokens off; ## Don't show the nginx version number, a security best practice
  59. return 301 https://$server_name$request_uri;
  60. access_log /var/log/nginx/gitlab_access.log;
  61. error_log /var/log/nginx/gitlab_error.log;
  62. }
  63.  
  64. ## HTTPS host
  65. server {
  66. listen 0.0.0.0:443 ssl;
  67. listen [::]:443 ipv6only=on ssl default_server;
  68. server_name HOSTNAME; ## Replace this with something like gitlab.example.com
  69. server_tokens off; ## Don't show the nginx version number, a security best practice
  70. root /opt/gitlab/embedded/service/gitlab-rails/public;
  71.  
  72. ## Increase this if you want to upload large attachments
  73. ## Or if you want to accept large git objects over http
  74. client_max_body_size 20m;
  75.  
  76. ## Strong SSL Security
  77. ## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/
  78. ssl on;
  79. ssl_certificate YOUR.crt;
  80. ssl_certificate_key YOUR.key;
  81.  
  82. # GitLab needs backwards compatible ciphers to retain compatibility with Java IDEs
  83. 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";
  84. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  85. ssl_prefer_server_ciphers on;
  86. #ssl_session_cache shared:SSL:10m;
  87. ssl_session_timeout 5m;
  88.  
  89. ## See app/controllers/application_controller.rb for headers set
  90.  
  91. ## [Optional] If your certficate has OCSP, enable OCSP stapling to reduce the overhead and latency of running SSL.
  92. ## Replace with your ssl_trusted_certificate. For more info see:
  93. ## - https://medium.com/devops-programming/4445f4862461
  94. ## - https://www.ruby-forum.com/topic/4419319
  95. ## - https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx
  96. # ssl_stapling on;
  97. # ssl_stapling_verify on;
  98. # ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt;
  99. # resolver 208.67.222.222 208.67.222.220 valid=300s; # Can change to your DNS resolver if desired
  100. # resolver_timeout 5s;
  101.  
  102. ## [Optional] Generate a stronger DHE parameter:
  103. ## sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 4096
  104. ##
  105. # ssl_dhparam /etc/ssl/certs/dhparam.pem;
  106.  
  107. ## Individual nginx logs for this GitLab vhost
  108. access_log /var/log/nginx/gitlab_access.log;
  109. error_log /var/log/nginx/gitlab_error.log;
  110.  
  111. location / {
  112. ## Serve static files from defined root folder.
  113. ## @gitlab is a named location for the upstream fallback, see below.
  114. try_files $uri $uri/index.html $uri.html @gitlab;
  115. }
  116.  
  117. ## We route uploads through GitLab to prevent XSS and enforce access control.
  118. location /uploads/ {
  119. ## If you use HTTPS make sure you disable gzip compression
  120. ## to be safe against BREACH attack.
  121. gzip off;
  122.  
  123. ## https://github.com/gitlabhq/gitlabhq/issues/694
  124. ## Some requests take more than 30 seconds.
  125. proxy_read_timeout 300;
  126. proxy_connect_timeout 300;
  127. proxy_redirect off;
  128.  
  129. proxy_set_header Host $http_host;
  130. proxy_set_header X-Real-IP $remote_addr;
  131. proxy_set_header X-Forwarded-Ssl on;
  132. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  133. proxy_set_header X-Forwarded-Proto $scheme;
  134. proxy_set_header X-Frame-Options SAMEORIGIN;
  135.  
  136. proxy_pass http://gitlab;
  137. }
  138.  
  139. ## If a file, which is not found in the root folder is requested,
  140. ## then the proxy passes the request to the upsteam (gitlab unicorn).
  141. location @gitlab {
  142. ## If you use HTTPS make sure you disable gzip compression
  143. ## to be safe against BREACH attack.
  144. gzip off;
  145.  
  146. ## https://github.com/gitlabhq/gitlabhq/issues/694
  147. ## Some requests take more than 30 seconds.
  148. proxy_read_timeout 300;
  149. proxy_connect_timeout 300;
  150. proxy_redirect off;
  151.  
  152. proxy_set_header Host $http_host;
  153. proxy_set_header X-Real-IP $remote_addr;
  154. proxy_set_header X-Forwarded-Ssl on;
  155. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  156. proxy_set_header X-Forwarded-Proto $scheme;
  157. proxy_set_header X-Frame-Options SAMEORIGIN;
  158.  
  159. proxy_pass http://gitlab;
  160. }
  161.  
  162. location ~ ^/[\w\.-]+/[\w\.-]+/gitlab-lfs/objects {
  163. client_max_body_size 0;
  164. # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
  165. error_page 418 = @gitlab-workhorse;
  166. return 418;
  167. }
  168.  
  169. location ~ ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$ {
  170. client_max_body_size 0;
  171. # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
  172. error_page 418 = @gitlab-workhorse;
  173. return 418;
  174. }
  175.  
  176. location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive {
  177. client_max_body_size 0;
  178. # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
  179. error_page 418 = @gitlab-workhorse;
  180. return 418;
  181. }
  182.  
  183. location ~ ^/api/v3/projects/.*/repository/archive {
  184. client_max_body_size 0;
  185. # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
  186. error_page 418 = @gitlab-workhorse;
  187. return 418;
  188. }
  189.  
  190. # Build artifacts should be submitted to this location
  191. location ~ ^/[\w\.-]+/[\w\.-]+/builds/download {
  192. client_max_body_size 0;
  193. # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
  194. error_page 418 = @gitlab-workhorse;
  195. return 418;
  196. }
  197.  
  198. # Build artifacts should be submitted to this location
  199. location ~ /ci/api/v1/builds/[0-9]+/artifacts {
  200. client_max_body_size 0;
  201. # 'Error' 418 is a hack to re-use the @gitlab-workhorse block
  202. error_page 418 = @gitlab-workhorse;
  203. return 418;
  204. }
  205.  
  206. location @gitlab-workhorse {
  207.  
  208. ## If you use HTTPS make sure you disable gzip compression
  209. ## to be safe against BREACH attack.
  210. gzip off;
  211.  
  212. ## https://github.com/gitlabhq/gitlabhq/issues/694
  213. ## Some requests take more than 30 seconds.
  214. proxy_read_timeout 300;
  215. proxy_connect_timeout 300;
  216. proxy_redirect off;
  217.  
  218. # Do not buffer Git HTTP responses
  219. proxy_buffering off;
  220.  
  221. # The following settings only work with NGINX 1.7.11 or newer
  222. #
  223. # # Pass chunked request bodies to gitlab-workhorse as-is
  224. # proxy_request_buffering off;
  225. # proxy_http_version 1.1;
  226.  
  227. proxy_set_header Host $http_host;
  228. proxy_set_header X-Real-IP $remote_addr;
  229. proxy_set_header X-Forwarded-Ssl on;
  230. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  231. proxy_set_header X-Forwarded-Proto $scheme;
  232. proxy_pass http://gitlab-workhorse;
  233. }
  234.  
  235. ## Enable gzip compression as per rails guide:
  236. ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  237. ## WARNING: If you are using relative urls remove the block below
  238. ## See config/application.rb under "Relative url support" for the list of
  239. ## other files that need to be changed for relative url support
  240. location ~ ^/(assets)/ {
  241. root /opt/gitlab/embedded/service/gitlab-rails/public;
  242. gzip_static on; # to serve pre-gzipped version
  243. expires max;
  244. add_header Cache-Control public;
  245. }
  246.  
  247. error_page 502 /502.html;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement