|
| 1 | +# Copy from pulp-oci-images. |
| 2 | +# Ideally we can get it upstream again. |
| 3 | +# |
| 4 | +# The "nginx" package on fedora creates this user and group. |
| 5 | +user nginx nginx; |
| 6 | +# Gunicorn docs suggest this value. |
| 7 | +worker_processes 1; |
| 8 | +daemon off; |
| 9 | +events { |
| 10 | + worker_connections 1024; # increase if you have lots of clients |
| 11 | + accept_mutex off; # set to 'on' if nginx worker_processes > 1 |
| 12 | +} |
| 13 | + |
| 14 | +http { |
| 15 | + include mime.types; |
| 16 | + # fallback in case we can't determine a type |
| 17 | + default_type application/octet-stream; |
| 18 | + sendfile on; |
| 19 | + |
| 20 | + # If left at the default of 1024, nginx emits a warning about being unable |
| 21 | + # to build optimal hash types. |
| 22 | + types_hash_max_size 4096; |
| 23 | + |
| 24 | + {%- if https | default(false) %} |
| 25 | + map $ssl_client_s_dn $ssl_client_s_dn_cn { |
| 26 | + default ""; |
| 27 | + ~CN=(?<CN>[^,]+) $CN; |
| 28 | + } |
| 29 | + {%- endif %} |
| 30 | + |
| 31 | + upstream pulp-content { |
| 32 | + server 127.0.0.1:24816; |
| 33 | + } |
| 34 | + |
| 35 | + upstream pulp-api { |
| 36 | + server 127.0.0.1:24817; |
| 37 | + } |
| 38 | + |
| 39 | + server { |
| 40 | + # Gunicorn docs suggest the use of the "deferred" directive on Linux. |
| 41 | + {% if https | default(false) -%} |
| 42 | + listen 443 default_server deferred ssl; |
| 43 | + |
| 44 | + ssl_certificate /etc/pulp/certs/pulp_webserver.crt; |
| 45 | + ssl_certificate_key /etc/pulp/certs/pulp_webserver.key; |
| 46 | + ssl_session_cache shared:SSL:50m; |
| 47 | + ssl_session_timeout 1d; |
| 48 | + ssl_session_tickets off; |
| 49 | + |
| 50 | + # intermediate configuration |
| 51 | + ssl_protocols TLSv1.2; |
| 52 | + ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256'; |
| 53 | + ssl_prefer_server_ciphers on; |
| 54 | + |
| 55 | + # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months) |
| 56 | + add_header Strict-Transport-Security max-age=15768000; |
| 57 | + |
| 58 | + # Configure client cert authentication |
| 59 | + ssl_client_certificate /etc/pulp/certs/ca.pem; |
| 60 | + ssl_verify_client optional; |
| 61 | + {%- else -%} |
| 62 | + listen 80 default_server deferred; |
| 63 | + {%- endif %} |
| 64 | + server_name $hostname; |
| 65 | + |
| 66 | + # The default client_max_body_size is 1m. Clients uploading |
| 67 | + # files larger than this will need to chunk said files. |
| 68 | + client_max_body_size 10m; |
| 69 | + |
| 70 | + # Gunicorn docs suggest this value. |
| 71 | + keepalive_timeout 5; |
| 72 | + |
| 73 | + location {{ content_path }} { |
| 74 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 75 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 76 | + proxy_set_header Host $http_host; |
| 77 | + # we don't want nginx trying to do something clever with |
| 78 | + # redirects, we set the Host: header above already. |
| 79 | + proxy_redirect off; |
| 80 | + proxy_pass http://pulp-content; |
| 81 | + } |
| 82 | + |
| 83 | + location {{ api_root }}api/v3/ { |
| 84 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 85 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 86 | + proxy_set_header Host $http_host; |
| 87 | + {%- if https | default(false) %} |
| 88 | + proxy_set_header Remoteuser $ssl_client_s_dn_cn; |
| 89 | + {%- endif %} |
| 90 | + # we don't want nginx trying to do something clever with |
| 91 | + # redirects, we set the Host: header above already. |
| 92 | + proxy_redirect off; |
| 93 | + proxy_pass http://pulp-api; |
| 94 | + client_max_body_size 0; |
| 95 | + } |
| 96 | + |
| 97 | + {%- if domain_enabled | default(false) %} |
| 98 | + location ~ {{ api_root }}.+/api/v3/ { |
| 99 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 100 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 101 | + proxy_set_header Host $http_host; |
| 102 | + # we don't want nginx trying to do something clever with |
| 103 | + # redirects, we set the Host: header above already. |
| 104 | + proxy_redirect off; |
| 105 | + proxy_pass http://pulp-api; |
| 106 | + client_max_body_size 0; |
| 107 | + } |
| 108 | + {%- endif %} |
| 109 | + |
| 110 | + location /auth/login/ { |
| 111 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 112 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 113 | + proxy_set_header Host $http_host; |
| 114 | + # we don't want nginx trying to do something clever with |
| 115 | + # redirects, we set the Host: header above already. |
| 116 | + proxy_redirect off; |
| 117 | + proxy_pass http://pulp-api; |
| 118 | + } |
| 119 | + |
| 120 | + include pulp/*.conf; |
| 121 | + |
| 122 | + location / { |
| 123 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 124 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 125 | + proxy_set_header Host $http_host; |
| 126 | + # we don't want nginx trying to do something clever with |
| 127 | + # redirects, we set the Host: header above already. |
| 128 | + proxy_redirect off; |
| 129 | + proxy_pass http://pulp-api; |
| 130 | + # most pulp static files are served through whitenoise |
| 131 | + # http://whitenoise.evans.io/en/stable/ |
| 132 | + } |
| 133 | + |
| 134 | + {%- if https | default(false) %} |
| 135 | + # ACME http-01 tokens, i.e, for Let's Encrypt |
| 136 | + location /.well-known/ { |
| 137 | + try_files $uri $uri/ =404; |
| 138 | + } |
| 139 | + {%- endif %} |
| 140 | + {% if https | default(false) -%} |
| 141 | + location /oauth2token/ { |
| 142 | + auth_basic "Tokens, Tokens, Tokens"; |
| 143 | + auth_basic_user_file /etc/pulp/certs/oauth2passwd; |
| 144 | + if ($request_method !~ POST) { |
| 145 | + # This still triggers earlier than the auth_basic in the outer block. |
| 146 | + return 403; |
| 147 | + } |
| 148 | + try_files /dev/null @oauth2token; |
| 149 | + } |
| 150 | + # Nginx "return" kicks in before basic_auth, so we must use it in a separate block. |
| 151 | + # https://stackoverflow.com/questions/67975464/why-doesnt-basic-auth-work-with-a-simple-nginx-return-statement |
| 152 | + location @oauth2token { |
| 153 | + default_type application/json; |
| 154 | + charset utf-8; |
| 155 | + |
| 156 | + return 200 '{"access_token": "DEADBEEF", "token_type": "bearer", "expires_in": 30}'; |
| 157 | + } |
| 158 | + {%- endif %} |
| 159 | + } |
| 160 | + {%- if https | default(false) %} |
| 161 | + server { |
| 162 | + listen 80 default_server; |
| 163 | + server_name _; |
| 164 | + return 301 https://$host$request_uri; |
| 165 | + } |
| 166 | + {%- endif %} |
| 167 | +} |
0 commit comments