mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
Merge pull request #6610 from ninjadq/add_customized_location_to_nginx
Add customized config file for proxy
This commit is contained in:
commit
9825711250
@ -33,6 +33,9 @@ http {
|
||||
# disable any limits to avoid HTTP 413 for large image uploads
|
||||
client_max_body_size 0;
|
||||
|
||||
# costumized location config file can place to /etc/nginx/etc with prefix harbor.http. and suffix .conf
|
||||
include /etc/nginx/conf.d/harbor.http.*.conf;
|
||||
|
||||
location / {
|
||||
proxy_pass http://portal/;
|
||||
proxy_set_header Host $$host;
|
||||
|
@ -50,6 +50,9 @@ http {
|
||||
# required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
|
||||
chunked_transfer_encoding on;
|
||||
|
||||
# costumized location config file can place to /etc/nginx dir with prefix harbor.https. and suffix .conf
|
||||
include /etc/nginx/conf.d/harbor.https.*.conf;
|
||||
|
||||
location / {
|
||||
proxy_pass http://portal/;
|
||||
proxy_set_header Host $$http_host;
|
||||
|
27
make/prepare
27
make/prepare
@ -4,6 +4,7 @@ from __future__ import print_function, unicode_literals # We require Python 2.6
|
||||
from string import Template
|
||||
import random
|
||||
import os
|
||||
from fnmatch import fnmatch
|
||||
import sys
|
||||
import string
|
||||
import argparse
|
||||
@ -27,6 +28,8 @@ base_dir = os.path.dirname(__file__)
|
||||
config_dir = os.path.join(base_dir, "common/config")
|
||||
templates_dir = os.path.join(base_dir, "common/templates")
|
||||
|
||||
custom_nginx_location_file_pattern = 'harbor.https.*.conf'
|
||||
|
||||
def validate(conf, args):
|
||||
|
||||
protocol = rcp.get("configuration", "ui_url_protocol")
|
||||
@ -308,8 +311,28 @@ if protocol == "https":
|
||||
ssl_cert = os.path.join("/etc/nginx/cert", os.path.basename(target_cert_path)),
|
||||
ssl_cert_key = os.path.join("/etc/nginx/cert", os.path.basename(target_cert_key_path)))
|
||||
else:
|
||||
render(os.path.join(templates_dir, "nginx", "nginx.http.conf"),
|
||||
nginx_conf)
|
||||
render(os.path.join(templates_dir, "nginx", "nginx.http.conf"), nginx_conf)
|
||||
custom_nginx_location_file_pattern = 'harbor.http.*.conf'
|
||||
|
||||
def add_additional_location_config(src, dst):
|
||||
"""
|
||||
This conf file is used for user that wanna add additional customized locations to harbor proxy
|
||||
:params src: source of the file
|
||||
:params dst: destination file path
|
||||
"""
|
||||
if not os.path.isfile(src):
|
||||
return
|
||||
print("Copying nginx configuration file {src} to {dst}".format(src=src, dst=dst))
|
||||
shutil.copy2(src, dst)
|
||||
mark_file(dst)
|
||||
|
||||
nginx_template_ext_dir = os.path.join(templates_dir, 'nginx', 'ext')
|
||||
if os.path.exists(nginx_template_ext_dir):
|
||||
map(lambda filename: add_additional_location_config(
|
||||
os.path.join(nginx_template_ext_dir, filename),
|
||||
os.path.join(nginx_conf_d, filename)),
|
||||
[fname for fname in os.listdir(nginx_template_ext_dir) if fnmatch(fname, custom_nginx_location_file_pattern)])
|
||||
|
||||
#Use reload_key to avoid reload config after restart harbor
|
||||
reload_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6)) if reload_config == "true" else ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user