Skip to content

Commit 4f30a33

Browse files
committed
assets: nginx bypass puma when accessing assets.
1 parent 2878a14 commit 4f30a33

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ FROM sameersbn/gitlab:18.1.1
22

33
# Override files
44
COPY assets/runtime/config/gitlabhq/gitlab.yml ${GITLAB_RUNTIME_DIR}/config/gitlabhq/gitlab.yml
5+
COPY assets/runtime/config/nginx/gitlab ${GITLAB_RUNTIME_DIR}/config/nginx/gitlab
56
COPY assets/runtime/functions ${GITLAB_RUNTIME_DIR}/functions

assets/runtime/config/nginx/gitlab

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
## GitLab
2+
##
3+
## Lines starting with two hashes (##) are comments with information.
4+
## Lines starting with one hash (#) are configuration parameters that can be uncommented.
5+
##
6+
##################################
7+
## CONTRIBUTING ##
8+
##################################
9+
##
10+
## If you change this file in a Merge Request, please also create
11+
## a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
12+
##
13+
###################################
14+
## configuration ##
15+
###################################
16+
##
17+
## See installation.md#using-https for additional HTTPS configuration details.
18+
19+
upstream gitlab-workhorse {
20+
server localhost:8181 fail_timeout=0;
21+
}
22+
23+
map $http_upgrade $connection_upgrade_gitlab {
24+
default upgrade;
25+
'' close;
26+
}
27+
28+
## Obfuscate access_token and private_token in access log
29+
map $request_uri $obfuscated_request_uri {
30+
~(.+\?)(.*&)?(private_token=|access_token=)[^&]*(&.*|$) $1$2$3****$4;
31+
default $request_uri;
32+
}
33+
log_format gitlab_access '$remote_addr - $remote_user [$time_local] '
34+
'"$request_method $obfuscated_request_uri $server_protocol" $status $body_bytes_sent '
35+
'"$http_referer" "$http_user_agent"';
36+
37+
## Normal HTTP host
38+
server {
39+
## Either remove "default_server" from the listen line below,
40+
## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
41+
## to be served if you visit any address that your server responds to, eg.
42+
## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
43+
listen 0.0.0.0:80 default_server;
44+
listen [::]:80 default_server;
45+
server_name {{GITLAB_HOST}}; ## Replace this with something like gitlab.example.com
46+
server_tokens off; ## Don't show the nginx version number, a security best practice
47+
48+
## See app/controllers/application_controller.rb for headers set
49+
50+
## Real IP Module Config
51+
## http://nginx.org/en/docs/http/ngx_http_realip_module.html
52+
real_ip_header X-Real-IP; ## X-Real-IP or X-Forwarded-For or proxy_protocol
53+
real_ip_recursive {{NGINX_REAL_IP_RECURSIVE}}; ## If you enable 'on'
54+
## If you have a trusted IP address, uncomment it and set it
55+
set_real_ip_from {{NGINX_REAL_IP_TRUSTED_ADDRESSES}}; ## Replace this with something like 192.168.1.0/24
56+
57+
add_header X-Accel-Buffering {{NGINX_ACCEL_BUFFERING}};
58+
add_header Strict-Transport-Security "max-age={{NGINX_HSTS_MAXAGE}};";
59+
60+
## Individual nginx logs for this GitLab vhost
61+
access_log {{GITLAB_LOG_DIR}}/nginx/gitlab_access.log gitlab_access;
62+
error_log {{GITLAB_LOG_DIR}}/nginx/gitlab_error.log;
63+
64+
location / {
65+
client_max_body_size 0;
66+
gzip off;
67+
68+
## https://github.com/gitlabhq/gitlabhq/issues/694
69+
## Some requests take more than 30 seconds.
70+
proxy_read_timeout 300;
71+
proxy_connect_timeout 300;
72+
proxy_redirect off;
73+
proxy_buffering {{NGINX_PROXY_BUFFERING}};
74+
75+
proxy_http_version 1.1;
76+
77+
proxy_set_header Host $http_host;
78+
proxy_set_header X-Real-IP $remote_addr;
79+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
80+
proxy_set_header X-Forwarded-Proto {{NGINX_X_FORWARDED_PROTO}};
81+
proxy_set_header Upgrade $http_upgrade;
82+
proxy_set_header Connection $connection_upgrade_gitlab;
83+
84+
proxy_pass http://gitlab-workhorse;
85+
}
86+
87+
error_page 404 /404.html;
88+
error_page 422 /422.html;
89+
error_page 500 /500.html;
90+
error_page 502 /502.html;
91+
error_page 503 /503.html;
92+
location /assets/ {
93+
alias {{GITLAB_INSTALL_DIR}}/public/assets/;
94+
expires max;
95+
add_header Cache-Control public;
96+
}
97+
location ~ ^/(404|422|500|502|503)\.html$ {
98+
root {{GITLAB_INSTALL_DIR}}/public;
99+
internal;
100+
}
101+
102+
{{NGINX_CUSTOM_GITLAB_SERVER_CONFIG}}
103+
}

assets/runtime/functions

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,10 @@ configure_nginx() {
21742174
-e "s|# server_names_hash_bucket_size 64;|server_names_hash_bucket_size ${NGINX_SERVER_NAMES_HASH_BUCKET_SIZE};|" \
21752175
/etc/nginx/nginx.conf
21762176

2177+
# https://github.com/ustclug/docker-gitlab/issues/4
2178+
echo "Adding nginx to ${GITLAB_USER} group..."
2179+
usermod -a -G ${GITLAB_USER} nginx
2180+
21772181
nginx_configure_gitlab
21782182
nginx_configure_gitlab_ci
21792183
nginx_configure_gitlab_registry

testdrive.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ check() {
5151
echo "Error: Failed to find 'example oauth' in gitlab.yml"
5252
return 1
5353
fi
54+
assets_location="/assets/locale/zh_CN/app-45e4963f833169170e6fd77b78bb1758d413a6a676d484235818594551d2e018.js"
55+
assets_code=$(curl --write-out '%{http_code}' --silent --output /dev/null "$url$assets_location")
56+
if [[ $assets_code -lt 200 || $assets_code -gt 399 ]]; then
57+
echo "Error: Failed to access $url$assets_location (status code: $assets_code)"
58+
return 1
59+
fi
5460
return 0
5561
}
5662

5763
RETRIES="48"
5864
RETRIED=0
5965
WAIT_TIME="5s"
6066

61-
until check || { [[ "$((RETRIED++))" == "${RETRIES}" ]] && exit 1; } ; do
67+
until check || { [[ "$((RETRIED++))" == "${RETRIES}" ]] && exit 1; }; do
6268
sleep "${WAIT_TIME}"
6369
done

0 commit comments

Comments
 (0)