├── .dockerignore ├── Dockerfile ├── Dockerfile.aarch64 ├── Dockerfile.armhf ├── LICENSE ├── README.md ├── default.conf ├── hooks ├── post_checkout ├── post_push └── pre_build ├── logo.png ├── multi-arch-manifest.yaml └── nginx.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | LICENSE 3 | README.md 4 | logo.png -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | MAINTAINER David Personette 3 | 4 | # Install nginx 5 | RUN version=$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release) && \ 6 | apk --no-cache --no-progress upgrade && \ 7 | apk --no-cache --no-progress add apache2-utils bash curl openssl shadow \ 8 | tini tzdata && \ 9 | addgroup -S nginx && \ 10 | adduser -S -D -H -h /var/cache/nginx -s /sbin/nologin -G nginx \ 11 | -g 'Nginx User' nginx && \ 12 | curl -LSs https://nginx.org/keys/nginx_signing.rsa.pub \ 13 | -o /etc/apk/keys/nginx_signing.rsa.pub && \ 14 | echo "https://nginx.org/packages/mainline/alpine/v${version}/main" \ 15 | >>/etc/apk/repositories && \ 16 | apk add --no-cache --no-progress nginx && \ 17 | sed -i 's/#gzip/gzip/' /etc/nginx/nginx.conf && \ 18 | sed -i "/http_x_forwarded_for\"';/s/';/ '/" /etc/nginx/nginx.conf && \ 19 | sed -i "/http_x_forwarded_for/a \\\ 20 | '\$request_time \$upstream_response_time';" \ 21 | /etc/nginx/nginx.conf && \ 22 | echo -e "\n\nstream {\n include /etc/nginx/conf.d/*.stream;\n}" \ 23 | >>/etc/nginx/nginx.conf && \ 24 | [ -d /srv/www ] || mkdir -p /srv/www && \ 25 | { mv /usr/share/nginx/html/index.html /srv/www/ || :; } && \ 26 | apk add --no-cache --no-progress --virtual .gettext gettext && \ 27 | mv /usr/bin/envsubst /usr/local/bin/ && \ 28 | runDeps="$(scanelf --needed --nobanner /usr/local/bin/envsubst | \ 29 | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' | \ 30 | sort -u | xargs -r apk info --installed | sort -u)" && \ 31 | apk del --no-cache --no-progress .gettext && \ 32 | apk add --no-cache --no-progress $runDeps && \ 33 | rm -rf /tmp/* && \ 34 | ln -sf /dev/stdout /var/log/nginx/access.log && \ 35 | ln -sf /dev/stderr /var/log/nginx/error.log 36 | # Forward request and error logs to docker log collector 37 | 38 | COPY default.conf /etc/nginx/conf.d/ 39 | COPY nginx.sh /usr/bin/ 40 | 41 | VOLUME ["/srv/www", "/etc/nginx"] 42 | 43 | EXPOSE 80 443 44 | 45 | HEALTHCHECK --interval=60s --timeout=15s --start-period=120s \ 46 | CMD curl -Lk 'https://localhost/index.html' 47 | 48 | ENTRYPOINT ["/sbin/tini", "--", "/usr/bin/nginx.sh"] -------------------------------------------------------------------------------- /Dockerfile.aarch64: -------------------------------------------------------------------------------- 1 | FROM arm64v8/nginx:alpine 2 | COPY qemu-aarch64-static /usr/bin/ 3 | MAINTAINER David Personette 4 | 5 | # Setup nginx 6 | RUN apk --no-cache --no-progress upgrade && \ 7 | apk --no-cache --no-progress add apache2-utils bash curl openssl shadow \ 8 | tini tzdata && \ 9 | sed -i 's/#gzip/gzip/' /etc/nginx/nginx.conf && \ 10 | sed -i "/http_x_forwarded_for\"';/s/';/ '/" /etc/nginx/nginx.conf && \ 11 | sed -i "/http_x_forwarded_for/a \\\ 12 | '\$request_time \$upstream_response_time';" \ 13 | /etc/nginx/nginx.conf && \ 14 | echo -e "\n\nstream {\n include /etc/nginx/conf.d/*.stream;\n}" \ 15 | >>/etc/nginx/nginx.conf && \ 16 | [ -d /srv/www ] || mkdir -p /srv/www && \ 17 | { mv /usr/share/nginx/html/index.html /srv/www/ || :; } && \ 18 | apk add --no-cache --no-progress --virtual .gettext gettext && \ 19 | mv /usr/bin/envsubst /usr/local/bin/ && \ 20 | runDeps="$(scanelf --needed --nobanner /usr/local/bin/envsubst | \ 21 | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' | \ 22 | sort -u | xargs -r apk info --installed | sort -u)" && \ 23 | apk del --no-cache --no-progress .gettext && \ 24 | apk add --no-cache --no-progress $runDeps && \ 25 | rm -rf /tmp/* && \ 26 | ln -sf /dev/stdout /var/log/nginx/access.log && \ 27 | ln -sf /dev/stderr /var/log/nginx/error.log 28 | # Forward request and error logs to docker log collector 29 | 30 | COPY default.conf /etc/nginx/conf.d/ 31 | COPY nginx.sh /usr/bin/ 32 | 33 | VOLUME ["/srv/www", "/etc/nginx"] 34 | 35 | EXPOSE 80 443 36 | 37 | HEALTHCHECK --interval=60s --timeout=15s --start-period=120s \ 38 | CMD curl -Lk 'https://localhost/index.html' 39 | 40 | ENTRYPOINT ["/sbin/tini", "--", "/usr/bin/nginx.sh"] -------------------------------------------------------------------------------- /Dockerfile.armhf: -------------------------------------------------------------------------------- 1 | FROM arm32v6/nginx:alpine 2 | COPY qemu-arm-static /usr/bin/ 3 | MAINTAINER David Personette 4 | 5 | # Setup nginx 6 | RUN apk --no-cache --no-progress upgrade && \ 7 | apk --no-cache --no-progress add apache2-utils bash curl openssl shadow \ 8 | tini tzdata && \ 9 | sed -i 's/#gzip/gzip/' /etc/nginx/nginx.conf && \ 10 | sed -i "/http_x_forwarded_for\"';/s/';/ '/" /etc/nginx/nginx.conf && \ 11 | sed -i "/http_x_forwarded_for/a \\\ 12 | '\$request_time \$upstream_response_time';" \ 13 | /etc/nginx/nginx.conf && \ 14 | echo -e "\n\nstream {\n include /etc/nginx/conf.d/*.stream;\n}" \ 15 | >>/etc/nginx/nginx.conf && \ 16 | [ -d /srv/www ] || mkdir -p /srv/www && \ 17 | { mv /usr/share/nginx/html/index.html /srv/www/ || :; } && \ 18 | apk add --no-cache --no-progress --virtual .gettext gettext && \ 19 | mv /usr/bin/envsubst /usr/local/bin/ && \ 20 | runDeps="$(scanelf --needed --nobanner /usr/local/bin/envsubst | \ 21 | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' | \ 22 | sort -u | xargs -r apk info --installed | sort -u)" && \ 23 | apk del --no-cache --no-progress .gettext && \ 24 | apk add --no-cache --no-progress $runDeps && \ 25 | rm -rf /tmp/* && \ 26 | ln -sf /dev/stdout /var/log/nginx/access.log && \ 27 | ln -sf /dev/stderr /var/log/nginx/error.log 28 | # Forward request and error logs to docker log collector 29 | 30 | COPY default.conf /etc/nginx/conf.d/ 31 | COPY nginx.sh /usr/bin/ 32 | 33 | VOLUME ["/srv/www", "/etc/nginx"] 34 | 35 | EXPOSE 80 443 36 | 37 | HEALTHCHECK --interval=60s --timeout=15s --start-period=120s \ 38 | CMD curl -Lk 'https://localhost/index.html' 39 | 40 | ENTRYPOINT ["/sbin/tini", "--", "/usr/bin/nginx.sh"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![logo](https://raw.githubusercontent.com/dperson/nginx/master/logo.png)](http://nginx.org) 2 | 3 | # nginx 4 | 5 | nginx docker container 6 | 7 | ## Fork of the main docker ["nginx"](https://registry.hub.docker.com/_/nginx/) 8 | 9 | ### With the following changes: 10 | 11 | * Entrypoint script to take care of most normal configuration needs 12 | * Sets up a self-signed SSL cert 13 | 14 | # What is Nginx? 15 | 16 | Nginx (pronounced "engine-x") is an open source reverse proxy server for HTTP, 17 | HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, 18 | and a web server (origin server). The nginx project started with a strong focus 19 | on high concurrency, high performance and low memory usage. It is licensed under 20 | the 2-clause BSD-like license and it runs on Linux, BSD variants, Mac OS X, 21 | Solaris, AIX, HP-UX, as well as on other \*nix flavors. It also has a proof of 22 | concept port for Microsoft Windows. 23 | 24 | [wikipedia.org/wiki/Nginx](https://wikipedia.org/wiki/Nginx) 25 | 26 | --- 27 | 28 | # How to use this image 29 | 30 | ## Exposing the port 31 | 32 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx 33 | 34 | Then you can hit `http://hostname:8080` or `http://host-ip:8080` in your 35 | browser. 36 | 37 | ## Hosting some local simple static content 38 | 39 | sudo docker run -it -p 80:80 -p 443:443 \ 40 | -v /some/path:/srv/www:ro -d dperson/nginx 41 | 42 | ## Complex configuration 43 | 44 | sudo docker run -it --rm dperson/nginx -h 45 | 46 | Usage: nginx.sh [-opt] [command] 47 | Options (fields in '[]' are optional, '<>' are required): 48 | -h This help 49 | -6 Disable IPv6 50 | -B "[on|off]" Enables/disables the proxy request buffer, 51 | so that requests are passed through [on/off] (Default on) 52 | -b "[location][;IP]" Configure basic auth for "location" 53 | possible arg: [location] (defaults to '/') 54 | [location] is the URI in nginx (IE: /wiki) 55 | [;IP] addresses that don't have to authenticate 56 | -C "" Configure Content Security Policy header 57 | -c "" Configure the client_max_body_size for uploads 58 | -e "" Configure EXPIRES header on static assets 59 | possible arg: "[timeout]" - timeout for cached files 60 | -f "" Configure fastcgi proxy and location 61 | required arg: ";" 62 | is hostname or IP to connect to 63 | is the URI in nginx (IE: /mediatomb) 64 | -g "" Generate a selfsigned SSL cert 65 | possible args: "[domain][;country][;state][;locality][;org]" 66 | domain - FQDN for server 67 | country - 2 letter country code 68 | state - state of server location 69 | locality - city 70 | org - company 71 | -P Configure Production mode (no server tokens) 72 | -p Configure PFS (Perfect Forward Secrecy) 73 | -H Configure HSTS (HTTPS Strict Transport Security) 74 | -I "" Include a configuration file 75 | required arg: "" 76 | to be included 77 | -i Enable SSI (Server Side Includes) 78 | -n set server_name [:oldname] 79 | -q quick (don't create certs) 80 | -R "" set header to stop robot indexing 81 | possible arg: "[tag]" 82 | all no restrictions (default) 83 | noindex don't show in search results or "Cached" link 84 | nofollow don't follow the links on this page 85 | none equivalent to noindex, nofollow 86 | noarchive don't show a "Cached" link in search results 87 | nosnippet don't show a snippet in the search results 88 | noodp don't use Open Directory project metadata 89 | notranslate don't offer translation of this page 90 | noimageindex don't index images on this page 91 | unavailable_after: [RFC-850 date/time] don't show after 92 | the specified date/time (RFC 850 format) 93 | -r "" Redirect a hostname to a URL 94 | required arg: ";" 95 | to listen for (Fully Qualified Domain Name) 96 | where to send the requests 97 | -S "" Configure SSL sessions 98 | possible arg: "[timeout]" - timeout for session reuse, IE 5m 99 | -s "" Configure SSL stapling 100 | required arg: cert(s) your CA uses for the OCSP check 101 | -T "[;protocol]" Configure a stream proxy 102 | required arg: "<[IP:]port>;" 103 | what (optional) IP and (required) port to listen on 104 | where to send the requests to : 105 | possible third arg: "[protocol]" 106 | [protocol] if not TCP, specify here (IE "udp") 107 | -t "" Configure timezone 108 | possible arg: "[timezone]" - zoneinfo timezone for container 109 | -U "" Configure a HTTP auth user 110 | required arg: "username;password" 111 | is the name the user enters for authorization 112 | is the password the user enters for authorization 113 | -u "" Configure UWSGI proxy and location 114 | required arg: ";" 115 | is how to contact UWSGI 116 | is the URI in nginx (IE: /wiki) 117 | -W "" Configure web proxy hostname and location 118 | required arg: "http:///;hosts" 119 | is how to contact the HTTP service 120 | is a comma separated list of host names (minimum of 1) 121 | NOTE: the webserver will listen, but DNS is still needed 122 | possible args: "[header value]" "[sockets]" 123 | [header value] set "header" to "value" on traffic going 124 | through the proxy 125 | [sockets] if set to "no" don't enable use of websockets 126 | -w "" Configure web proxy and location 127 | required arg: "http:///;//" 128 | is how to contact the HTTP service 129 | is the URI in nginx (IE: /mediatomb) 130 | possible args: "[header value]" "[sockets]" 131 | [header value] set "header" to "value" on traffic going 132 | through the proxy 133 | [sockets] if set to "no" don't enable use of websockets 134 | 135 | The 'command' (if provided and valid) will be run instead of nginx 136 | 137 | ENVIRONMENT VARIABLES 138 | 139 | * `IPV6` - As above, disables IPv6 support 140 | * `BASIC` - As above, setup basic auth for URI location, IE `/path` 141 | * `EXPIRES` - As above, configure EXPIRES header on static assets 142 | * `FASTCGI` - As above, configure a fastcgi proxy 143 | * `GENCERT` - As above, make selfsigned SSL cert 144 | * `PFS` - As above, configure Perfect Forward Secracy 145 | * `PROD` - As above, production server flags 146 | * `HSTS` - As above, HTTPS Strict Transport Security 147 | * `INCLUDE` - As above, file to be included in configuration 148 | * `SSI` - As above, enable SSI (Server Side Includes) 149 | * `NAME` - As above, set servername 150 | * `OUICK` - As above, don't generate SSL cert 151 | * `REDIRECT` - As above, configure redirect `port;hostname;https://dest/url` 152 | * `ROBOT` - As above, set header to stop robot indexing 153 | * `STREAM` - As above, configure a stream proxy 154 | * `STAPLING` - As above, configure SSL stapling 155 | * `SSL_SESSIONS` - As above, setup SSL session reuse 156 | * `TZ` - As above, configure the zoneinfo timezone, IE `EST5EDT` 157 | * `HTTPUSER` - As above, configure HTTP user `username;password` (See NOTE2) 158 | * `USWGI` - As above, configure UWSGI app `http://dest:port/url;/path` 159 | * `PROXY` - As above, configure proxy to app `http://dest/url/;/path/` 160 | * `PROXY_HOST` - As above, configure proxy to app `http://dest/url/;host.name/` 161 | * `PROXYBUFFER` - Enables or disabled the proxy request buffer `[on|off]` 162 | * `USERID` - Set the UID for the webserver user 163 | * `GROUPID` - Set the GID for the webserver user 164 | * `CLIENTMAXBODYSIZE` - Set the max file size for uploads 165 | * `CONTENTSECURITY` - Set a CSP (Content Security Policy) 166 | 167 | **NOTE**: The `-r`/`REDIRECT` no longer require the port be specified. 168 | 169 | **NOTE2**: optionally supports additional variables starting with the same name, 170 | IE `HTTPUSER` also will work for `HTTPUSER2`, `HTTPUSER3`... `HTTPUSERx`, etc. 171 | 172 | ## Examples 173 | 174 | Any of the commands can be run at creation with `docker run` or later with 175 | `docker exec -it nginx nginx.sh` (as of version 1.3 of docker). 176 | 177 | ### Start nginx with your real CA certs and setup SSL stapling: 178 | 179 | sudo docker run -it --name web -p 80:80 -p 443:443 -d dperson/nginx -q 180 | sudo docker exec -it web nginx.sh -q -s echo Stapling configured 181 | 182 | Will get you the same settings as 183 | 184 | sudo docker run -it --name web -p 80:80 -p 443:443 -d dperson/nginx -q -s 185 | 186 | Then run 187 | 188 | cat /path/to/your.cert.file | \ 189 | sudo docker exec -it web tee /etc/nginx/ssl/fullchain.pem 190 | cat /path/to/your.key.file | \ 191 | sudo docker exec -it web tee /etc/nginx/ssl/privkey.pem 192 | cat /path/to/your.ocsp.file | \ 193 | sudo docker exec -it web tee /etc/nginx/ssl/chain.pem 194 | sudo docker restart web 195 | 196 | ### Start a wiki running in an uwsgi container behind nginx: 197 | 198 | sudo docker run -it --name wiki -d dperson/moinmoin 199 | sudo docker run -it -p 80:80 -p 443:443 --link wiki:wiki -d dperson/nginx \ 200 | -u "wiki:3031;/wiki" 201 | 202 | OR 203 | 204 | sudo docker run -it --name wiki -d dperson/moinmoin 205 | sudo docker run -it -p 80:80 -p 443:443 --link wiki:wiki \ 206 | -e UWSGI="wiki:3031;/wiki" -d dperson/nginx 207 | 208 | ### Start nginx with a redirect: 209 | 210 | nginx will listen on a port for the hostname, and redirect to a different URL 211 | format (port;hostname;destination) 212 | 213 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx \ 214 | -r "80;myapp.example.com;https://myapp.herokuapp.com" \ 215 | -r "443;myapp.example.com;https://myapp.herokuapp.com" 216 | 217 | ENVIRONMENT variables don't support multiple values, use args as above 218 | 219 | ### Start nginx with a web proxy: 220 | 221 | sudo docker run -it --name smokeping -d dperson/smokeping 222 | sudo docker run -it -p 80:80 -p 443:443 --link smokeping:smokeping \ 223 | -d dperson/nginx -w "http://smokeping/smokeping/;/smokeping/" 224 | 225 | OR 226 | 227 | sudo docker run -it --name smokeping -d dperson/smokeping 228 | sudo docker run -it -p 80:80 -p 443:443 --link smokeping:smokeping \ 229 | -e PROXY="http://smokeping/smokeping/;/smokeping/" \ 230 | -d dperson/nginx 231 | 232 | ### Start nginx with a specified zoneinfo timezone: 233 | 234 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx -t EST5EDT 235 | 236 | OR 237 | 238 | sudo docker run -it -p 80:80 -p 443:443 -e TZ=EST5EDT -d dperson/nginx 239 | 240 | ### Start nginx with a defined hostname (instead of 'localhost'): 241 | 242 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx -n "example.com" 243 | 244 | OR 245 | 246 | sudo docker run -it -p 80:80 -p 443:443 -e NAME="example.com" \ 247 | -d dperson/nginx 248 | 249 | ### Start nginx with server tokens disabled (Production mode): 250 | 251 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx -P 252 | 253 | OR 254 | 255 | sudo docker run -it -p 80:80 -p 443:443 -e PROD=y -d dperson/nginx 256 | 257 | ### Start nginx with X-Robots-Tag header (block indexing): 258 | 259 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx -R 260 | 261 | OR 262 | 263 | sudo docker run -it -p 80:80 -p 443:443 -e ROBOT=y -d dperson/nginx 264 | 265 | ### Start nginx with SSI (Server Side Includes) enabled: 266 | 267 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx -i 268 | 269 | OR 270 | 271 | sudo docker run -it -p 80:80 -p 443:443 -e SSI=y -d dperson/nginx 272 | 273 | ### Start nginx with Perfect Forward Secrecy and HTTP Strict Transport Security: 274 | 275 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx -p -H 276 | 277 | OR 278 | 279 | sudo docker run -it -p 80:80 -p 443:443 -e PFS=1 -e HSTS=y -d dperson/nginx 280 | 281 | ### Start nginx with SSL Sessions (better performance for clients): 282 | 283 | sudo docker run -it -p 80:80 -p 443:443 -d dperson/nginx -S "" 284 | 285 | OR 286 | 287 | sudo docker run -it -p 80:80 -p 443:443 -e SSL_SESSIONS=5m -d dperson/nginx 288 | 289 | --- 290 | 291 | For information on the syntax of the Nginx configuration files, see 292 | [the official documentation](http://nginx.org/en/docs/) (specifically the 293 | [Beginner's Guide](http://nginx.org/en/docs/beginners_guide.html#conf_structure)). 294 | 295 | If you wish to adapt the default configuration, use something like the following 296 | to copy it from a running container: 297 | 298 | sudo docker cp web:/etc/nginx/nginx.conf /some/nginx.conf 299 | 300 | # User Feedback 301 | 302 | ## Issues 303 | 304 | If you have any problems with or questions about this image, please contact me 305 | through a [GitHub issue](https://github.com/dperson/nginx/issues). -------------------------------------------------------------------------------- /default.conf: -------------------------------------------------------------------------------- 1 | # You may add here your 2 | # server { 3 | # ... 4 | # } 5 | # statements for each of your virtual hosts to this file 6 | 7 | ## 8 | # You should look at the following URL's in order to grasp a solid understanding 9 | # of Nginx configuration files in order to fully unleash the power of Nginx. 10 | # http://wiki.nginx.org/Pitfalls 11 | # http://wiki.nginx.org/QuickStart 12 | # http://wiki.nginx.org/Configuration 13 | # 14 | # Generally, you will want to move this file somewhere, and start with a clean 15 | # file but keep this around for reference. Or just disable in sites-enabled. 16 | # 17 | # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. 18 | ## 19 | 20 | proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=mmcache:10m 21 | loader_threshold=300 loader_files=200 max_size=50m; 22 | 23 | 24 | # HTTPS server 25 | # 26 | server { 27 | listen 443 ssl http2 default_server; 28 | listen [::]:443 ssl http2 default_server; 29 | root /srv/www; 30 | 31 | ssl_certificate /etc/nginx/ssl/fullchain.pem; 32 | ssl_certificate_key /etc/nginx/ssl/privkey.pem; 33 | 34 | # Make site accessible from http://localhost/ 35 | server_name localhost; 36 | 37 | #charset koi8-r; 38 | #access_log /var/log/nginx/log/host.access.log main; 39 | error_log stderr; 40 | proxy_cache mmcache; 41 | 42 | location / { 43 | index index.html index.htm; 44 | 45 | # First attempt to serve request as file, then 46 | # as directory, then fall back to displaying a 404. 47 | try_files $uri $uri/ =404; 48 | } 49 | 50 | location = /robots.txt { 51 | allow all; 52 | log_not_found off; 53 | access_log off; 54 | } 55 | 56 | ## Handle the GFC (Great Firewal of China) breaking DNS for BT to random IPs 57 | location /announc { 58 | access_log off; 59 | error_log off; 60 | default_type text/plain; 61 | return 410 "d14:failure reason13:not a tracker8:retry in5:nevere"; 62 | } 63 | 64 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80 65 | # 66 | #location ~ \.php$ { 67 | # proxy_pass http://127.0.0.1; 68 | #} 69 | 70 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 71 | # 72 | #location ~ \.php$ { 73 | # root html; 74 | # fastcgi_split_path_info ^(.+\.php)(/.+)$; 75 | # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 76 | # 77 | # # With php5-cgi alone: 78 | # fastcgi_pass 127.0.0.1:9000; 79 | # # With php5-fpm: 80 | # fastcgi_pass unix:/run/php5-fpm.sock; 81 | # fastcgi_index index.php; 82 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 83 | # include fastcgi_params; 84 | #} 85 | 86 | # deny access to .htaccess files, if Apache's document root 87 | # concurs with nginx's one 88 | # 89 | #location ~ /\.ht { 90 | # deny all; 91 | #} 92 | 93 | #error_page 404 /404.html; 94 | 95 | # redirect server error pages to the static page /50x.html 96 | # 97 | error_page 500 502 503 504 /50x.html; 98 | location = /50x.html { 99 | root /usr/share/nginx/html; 100 | } 101 | } 102 | 103 | 104 | server { 105 | listen 80; 106 | listen [::]:80; 107 | root /srv/www; 108 | 109 | # Make site accessible from http://localhost/ 110 | server_name localhost; 111 | 112 | #charset koi8-r; 113 | #access_log /var/log/nginx/log/host.access.log main; 114 | error_log stderr notice; 115 | proxy_cache mmcache; 116 | 117 | location / { 118 | index index.html index.htm; 119 | 120 | # First attempt to serve request as file, then 121 | # as directory, then fall back to displaying a 404. 122 | try_files $uri $uri/ =404; 123 | } 124 | 125 | location = /robots.txt { 126 | allow all; 127 | log_not_found off; 128 | access_log off; 129 | } 130 | 131 | ## Handle the GFC (Great Firewal of China) breaking DNS for BT to random IPs 132 | location /announc { 133 | access_log off; 134 | error_log off; 135 | default_type text/plain; 136 | return 410 "d14:failure reason13:not a tracker8:retry in5:nevere"; 137 | } 138 | 139 | #error_page 404 /404.html; 140 | 141 | # redirect server error pages to the static page /50x.html 142 | # 143 | error_page 500 502 503 504 /50x.html; 144 | location = /50x.html { 145 | root /usr/share/nginx/html; 146 | } 147 | } 148 | 149 | 150 | # another virtual host using mix of IP-, name-, and port-based configuration 151 | # 152 | #server { 153 | # listen 8000; 154 | # listen somename:8080; 155 | # server_name somename alias another.alias; 156 | # root html; 157 | # index index.html index.htm; 158 | # 159 | # location / { 160 | # try_files $uri $uri/ =404; 161 | # } 162 | #} -------------------------------------------------------------------------------- /hooks/post_checkout: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | API="https://api.github.com/repos/estesp/manifest-tool/tags" 4 | URL="https://github.com/estesp/manifest-tool/releases/download" 5 | TAG=$(curl -Ls $API | awk -F'"' '/name.*v[0-9]/ {print $4; exit}') 6 | curl -LSso manifest-tool "${URL}/${TAG}/manifest-tool-linux-amd64" 7 | chmod +x manifest-tool 8 | 9 | [[ "${DOCKER_TAG}" == "amd64" ]] && \ 10 | { echo 'qemu-user-static: Download not required for this arch'; exit 0; } 11 | 12 | API="https://api.github.com/repos/multiarch/qemu-user-static/tags" 13 | URL="https://github.com/multiarch/qemu-user-static/releases/download" 14 | TAG=$(curl -Ls $API | awk -F'"' '/name.*v[0-9]/ {print $4; exit}') 15 | ARCH=$([[ "${DOCKER_TAG}" == "armhf" ]] && \ 16 | echo "${DOCKER_TAG::-2}" || echo "${DOCKER_TAG}") 17 | 18 | curl -LSs "${URL}/${TAG}/x86_64_qemu-${ARCH}-static.tar.gz" | tar xzv -------------------------------------------------------------------------------- /hooks/post_push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Use manifest-tool to create the manifest, given the experimental 4 | # "docker manifest" command isn't available yet on Docker Hub. 5 | 6 | ./manifest-tool push from-spec multi-arch-manifest.yaml --ignore-missing -------------------------------------------------------------------------------- /hooks/pre_build: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | [[ "${DOCKER_TAG}" == "amd64" ]] && \ 4 | { echo 'qemu-user-static: Registration not required for this arch';exit 0; } 5 | 6 | docker run --rm --privileged multiarch/qemu-user-static:register --reset -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dperson/nginx/aff6c521f24964c8ab585cf3740ddee254c3ff4b/logo.png -------------------------------------------------------------------------------- /multi-arch-manifest.yaml: -------------------------------------------------------------------------------- 1 | image: dperson/nginx:latest 2 | manifests: 3 | - image: dperson/nginx:amd64 4 | platform: 5 | architecture: amd64 6 | os: linux 7 | - image: dperson/nginx:aarch64 8 | platform: 9 | architecture: arm64 10 | os: linux 11 | variant: v8 12 | - image: dperson/nginx:armhf 13 | platform: 14 | architecture: arm 15 | os: linux 16 | variant: v6 -------------------------------------------------------------------------------- /nginx.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #=============================================================================== 3 | # FILE: nginx.sh 4 | # 5 | # USAGE: ./nginx.sh 6 | # 7 | # DESCRIPTION: Entrypoint for nginx docker container 8 | # 9 | # OPTIONS: --- 10 | # REQUIREMENTS: --- 11 | # BUGS: --- 12 | # NOTES: --- 13 | # AUTHOR: David Personette (dperson@gmail.com), 14 | # ORGANIZATION: 15 | # CREATED: 09/28/2014 12:11 16 | # REVISION: 1.1 17 | #=============================================================================== 18 | 19 | set -o nounset # Treat unset variables as an error 20 | 21 | ### basic: Basic Auth 22 | # Arguments: 23 | # location) optional location for basic auth 24 | # IP) optionl range(s) to allow without auth 25 | # Return: configure Basic Auth 26 | basic() { local loc="${1:-\\/}" dav file=/etc/nginx/conf.d/default.conf 27 | shift 28 | [[ ${1:-""} =~ ^dav ]] && { 29 | dav="$(sed 's/^dav#//; s/#/ /g' <<< ${1:-""})"; shift; } 30 | 31 | grep -q '^[^#]*location '"$loc" $file || 32 | sed -i '/location \/ /,/^ }/ { /^ }/a\ 33 | \ 34 | location '"$loc"' {\ 35 | autoindex on;\ 36 | } 37 | }' $file 38 | 39 | sed -n '/location '"$(sed 's|/|\\/|g' <<< $loc)"' /,/^ }/p' $file | 40 | grep -q auth_basic || 41 | sed -i '/location '"$(sed 's|/|\\/|g' <<<$loc)"' /,/^ }/ { /^ }/i\ 42 | '"$([[ ${dav:-""} ]] && echo '\' && echo " create_full_put_path on;\\" && 43 | echo " dav_access $dav;\\" && 44 | echo " dav_methods PUT DELETE MKCOL COPY MOVE;\\" 45 | [[ ${1:-""} ]] && echo '\'; for i; do 46 | echo -e ' allow '"$i"';\' 47 | done; [[ ${1:-""} ]] && echo ' ')"'\ 48 | auth_basic "restricted access";\ 49 | auth_basic_user_file /etc/nginx/htpasswd;\ 50 | \ 51 | satisfy any; 52 | }' $file 53 | } 54 | 55 | ### client_max_body_size: set a max body size for large uploads 56 | # Arguments: 57 | # none) 58 | # Return: The set body size 59 | client_max_body_size() { local value="${1:-100M}" \ 60 | file=/etc/nginx/conf.d/body_size.conf 61 | cat >$file <<-EOF 62 | # Set the client_max_body_size for large uploads 63 | # This can be represented as 10M for 10 MB rather than in bytes 64 | client_max_body_size $value; 65 | EOF 66 | } 67 | 68 | ### content_security: set a Content Security Policy header 69 | # Arguments: 70 | # policy) optional policy 71 | # Return: The set body size 72 | content_security() { local policy="${1:-default-src: https: 'unsafe-inline'}" \ 73 | file=/etc/nginx/conf.d/content_security.conf 74 | cat >$file <<-EOF 75 | # Set a Content Security Policy header 76 | add_header Content-Security-Policy "$policy"; 77 | EOF 78 | } 79 | 80 | ### proxy_request_buffering: set a max body size for large uploads 81 | # Arguments: 82 | # none) 83 | # Return: The set proxy request buffer state 84 | proxy_request_buffering() { local value="$1" \ 85 | file=/etc/nginx/conf.d/proxy_request_buffering.conf 86 | cat >$file <<-EOF 87 | # Disabled or enables the proxy_request_buffering, which is 88 | # useful for large uploads. This can be represented as either 89 | # on or off 90 | proxy_request_buffering $value; 91 | EOF 92 | } 93 | 94 | ### gencert: Generate SSL cert 95 | # Arguments: 96 | # domain) FQDN for server 97 | # country) 2 letter country code 98 | # state) state of server location 99 | # locality) city 100 | # org) company 101 | # Return: self-signed certs will be generated 102 | gencert() { local domain="${1:-*}" country="${2:-NO}" state="${3:-Rogaland}" \ 103 | locality="${4:-Sola}" org="{5:-None}" dir=/etc/nginx/ssl 104 | local cert="$dir/fullchain.pem" key="$dir/privkey.pem" 105 | [[ -e $cert ]] && return 106 | [[ -d $dir ]] || mkdir -p $dir 107 | 108 | openssl req -x509 -newkey rsa:2048 -keyout $key -out $cert -days 3600 \ 109 | -nodes -subj "/C=$country/ST=$state/L=$locality/O=$org/CN=$domain" 110 | } 111 | 112 | ### ipv6: disables ipv6 113 | # Arguments: 114 | # none) 115 | # Return: disables ipv6 116 | ipv6() { local file=/etc/nginx/conf.d/default.conf 117 | sed -i '/::/d' $file 118 | } 119 | 120 | ### pfs: Perfect Forward Secrecy 121 | # Arguments: 122 | # none) 123 | # Return: setup PFS config 124 | pfs() { local dir=/etc/nginx; local cert="$dir/ssl/ffdhe4096.pem" \ 125 | file="$dir/conf.d/perfect_forward_secrecy.conf" 126 | [[ -d $dir/ssl ]] || mkdir -p $dir/ssl 127 | 128 | [[ -e $cert ]] || 129 | echo -n '-----BEGIN DH PARAMETERS----- 130 | MIICCAKCAgEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz 131 | +8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a 132 | 87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 133 | YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi 134 | 7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD 135 | ssbzSibBsu/6iGtCOGEfz9zeNVs7ZRkDW7w09N75nAI4YbRvydbmyQd62R0mkff3 136 | 7lmMsPrBhtkcrv4TCYUTknC0EwyTvEN5RPT9RFLi103TZPLiHnH1S/9croKrnJ32 137 | nuhtK8UiNjoNq8Uhl5sN6todv5pC1cRITgq80Gv6U93vPBsg7j/VnXwl5B0rZp4e 138 | 8W5vUsMWTfT7eTDp5OWIV7asfV9C1p9tGHdjzx1VA0AEh/VbpX4xzHpxNciG77Qx 139 | iu1qHgEtnmgyqQdgCpGBMMRtx3j5ca0AOAkpmaMzy4t6Gh25PXFAADwqTs6p+Y0K 140 | zAqCkc3OyX3Pjsm1Wn+IpGtNtahR9EGC4caKAH5eZV9q//////////8CAQI= 141 | -----END DH PARAMETERS-----' >$cert 142 | echo "ssl_dhparam $cert;" >>$file 143 | echo '' >>$file 144 | 145 | echo -n "ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:" >>$file 146 | echo -n "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:" >>$file 147 | echo -n "ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:" >>$file 148 | echo -n "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:" >>$file 149 | echo -n "ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:" >>$file 150 | echo -n "ECDHE-RSA-AES128-SHA256:" >>$file 151 | echo "!DSS:!aNULL:!eNULL:!EXPORT:!RC4:!DES:!3DES:!SSLv2:!MD5:!PSK';" >>$file 152 | grep -rq ssl_prefer_server_ciphers /etc/nginx || 153 | echo 'ssl_prefer_server_ciphers on;' >>$file 154 | grep -rq ssl_protocols /etc/nginx || 155 | echo "ssl_protocols TLSv1.2;" >>$file 156 | } 157 | 158 | ### prod: Production mode 159 | # Arguments: 160 | # none) 161 | # Return: Turn off server tokens 162 | prod() { local file=/etc/nginx/nginx.conf 163 | sed -i '/# *server_tokens/s|# *||' $file 164 | grep -q server_tokens $file || sed -i '/^ *sendfile/ i\ 165 | server_tokens off;' $file 166 | sed -i 's|\(^ *server_tokens *\).*|\1off;|' $file 167 | } 168 | 169 | ### hsts: HTTP Strict Transport Security 170 | # Arguments: 171 | # none) 172 | # Return: configure HSTS 173 | hsts() { local file=/etc/nginx/conf.d/hsts.conf \ 174 | file2=/etc/nginx/conf.d/default.conf 175 | cat >$file <<-EOF 176 | # HTTP Strict Transport Security (HSTS) 177 | add_header Strict-Transport-Security \ 178 | "max-age=15768000; includeSubDomains; preload" always; 179 | add_header Front-End-Https "on" always; 180 | 181 | # This will prevent certain click-jacking attacks, but will prevent 182 | # other sites from framing your site, so delete or modify as necessary! 183 | add_header X-Content-Type-Options "nosniff" always; 184 | add_header X-Download-Options "noopen" always; 185 | add_header X-Frame-Options "SAMEORIGIN" always; 186 | add_header X-Permitted-Cross-Domain-Policies "none"; 187 | 188 | # Header enables the Cross-site scripting (XSS) filter in most browsers. 189 | # This will re-enable it for this website if it was user disabled. 190 | add_header X-XSS-Protection "1; mode=block" always; 191 | EOF 192 | sed -i '/^ *listen 80/,/^}/ { /proxy_cache/,/^}/c\ 193 | \ 194 | location ^~ /\.well-known/ {\ 195 | break;\ 196 | }\ 197 | rewrite ^(.*) https://$host$1 permanent;\ 198 | } 199 | }' $file2 200 | } 201 | 202 | ### http_user: HTTP auth user 203 | # Arguments: 204 | # user) user name for authentication 205 | # pass) password for authentication 206 | # Return: configure HTTP auth user 207 | http_user() { local user="$1" pass="$2" file=/etc/nginx/htpasswd 208 | [[ -e $file ]] || touch $file 209 | htpasswd -b $file "$user" "$pass" &>/dev/null 210 | } 211 | 212 | ### name: Set server_name 213 | # Arguments: 214 | # name) new server name 215 | # oldname) old name to change from (defaults to localhost) 216 | # Return: configure server_name 217 | name() { local name="$1" oldname="${2:-localhost}" \ 218 | file=/etc/nginx/conf.d/default.conf 219 | sed -i 's|\(^ *server_name\) '"$oldname"';|\1 '"$name"';|' $file 220 | } 221 | 222 | ### ssi: Server Side Includes 223 | # Arguments: 224 | # none) 225 | # Return: configure SSI 226 | ssi() { local file=/etc/nginx/conf.d/default.conf 227 | sed -n '/location \/ /,/^ }/p' $file | grep -q ssi || 228 | sed -i '/location \/ /,/^ }/ { /^ }/i\ 229 | \ 230 | ssi on; 231 | }' $file 232 | } 233 | 234 | ### redirect: redirect to another host 235 | # Arguments: 236 | # hostname) where to listen 237 | # destination) where to send the request 238 | # Return: hostname redirect added to config 239 | redirect() { [[ $1 =~ ^[0-9]*$ ]] && shift; local hostname="$1" \ 240 | destination="$2" file=/etc/nginx/conf.d/default.conf 241 | sed -n '/^server {/,/^}/p' $file | grep -q "rewrite.*$destination" || 242 | sed -i '/^server {/,/^}/ { n; /rewrite.*https.*\$host.*}/b; /^}/i\ 243 | \ 244 | if ($hostname ~ '"$hostname"') {\ 245 | rewrite ^(.*) '"$destination"'$1 permanent;\ 246 | } 247 | }' $file 248 | } 249 | 250 | ### robot: set header that works like robots.txt 251 | # Arguments: 252 | # none) 253 | # Return: configure HSTS 254 | robot() { local tag="${1:-none}" file=/etc/nginx/conf.d/robot.conf 255 | cat >$file <<-EOF 256 | # X-Robots-Tag 257 | # Directive Meaning 258 | # all no restrictions for indexing / serving (default) 259 | # noindex don't show in search results or a "Cached" link 260 | # nofollow don't follow the links on this page 261 | # none equivalent to noindex, nofollow 262 | # noarchive don't show a "Cached" link in search results 263 | # nosnippet don't show a snippet in the search results 264 | # noodp don't use Open Directory project metadata 265 | # notranslate don't offer translation of this page 266 | # noimageindex don't index images on this page 267 | # unavailable_after: [RFC-850 date/time] don't show after 268 | # the specified date/time (RFC 850 format) 269 | add_header X-Robots-Tag $tag; 270 | EOF 271 | } 272 | 273 | ### stream: Configure a stream proxy 274 | # Arguments: 275 | # server) where to listen for connections 276 | # dest) where to forward connections 277 | # Return: stream added to the config file 278 | stream() { local server="$1" dest="$2" proto="${3:-""}" \ 279 | file=/etc/nginx/conf.d/default.stream 280 | if grep -q "server { listen $server${proto:+ $proto};" $file; then 281 | sed -i '/^[^#]*server { listen '"$server${proto:+ $proto}"';/,/^}/d' \ 282 | $file 283 | fi 284 | echo -e "server { listen $server${proto:+ $proto};\n}" >>$file 285 | 286 | sed -i '/^[^#]*server { listen '"$server${proto:+ $proto}"';/a\ 287 | proxy_connect_timeout 10s;\ 288 | proxy_timeout 1800s;\ 289 | proxy_pass '"$dest"';' $file 290 | } 291 | 292 | ### ssl_sessions: Setup SSL session resumption 293 | # Arguments: 294 | # timeout) how long to keep the session open 295 | # Return: configure SSL sessions 296 | ssl_sessions() { local timeout="${1:-1d}" file=/etc/nginx/conf.d/sessions.conf 297 | echo '# Session resumption (caching)' >$file 298 | echo 'ssl_session_cache shared:SSL:50m;' >>$file 299 | echo "ssl_session_tickets off;" >>$file 300 | echo "ssl_session_timeout $timeout;" >>$file 301 | } 302 | 303 | ### stapling: SSL stapling 304 | # Arguments: 305 | # cert) full path to cert file 306 | # Return: configure SSL stapling 307 | stapling() { local dir=/etc/nginx/ssl file=/etc/nginx/conf.d/stapling.conf 308 | local cert="${1:-$dir/chain.pem}" 309 | 310 | [[ -e $cert ]] || { echo "ERROR: invalid stapling cert: $cert" >&2;return; } 311 | 312 | echo '# OCSP (Online Certificate Status Protocol) SSL stapling' >$file 313 | echo 'ssl_stapling on;' >>$file 314 | echo 'ssl_stapling_verify on;' >>$file 315 | echo "ssl_trusted_certificate $cert;" >>$file 316 | echo 'resolver 8.8.4.4 8.8.8.8 valid=300s;' >>$file 317 | echo 'resolver_timeout 5s;' >>$file 318 | } 319 | 320 | ### static: Setup long EXPIRES header on static assets 321 | # Arguments: 322 | # timeout) how long to keep the cached files 323 | # Return: configured static asset caching 324 | static() { local timeout="${1:-30d}" file=/etc/nginx/conf.d/default.conf 325 | sed -i '/^ ## Optional: set long EXPIRES/,/^ *$/d' $file 326 | sed -i '/^ #error_page/i\ 327 | ## Optional: set long EXPIRES header on static assets\ 328 | location ~* \\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {\ 329 | expires '"$timeout"';\ 330 | add_header Cache-Control private;\ 331 | ## Optional: Do not log access to assets\ 332 | access_log off;\ 333 | }\ 334 | ' $file 335 | } 336 | 337 | ### fastcgi: Configure a fastcgi proxy 338 | # Arguments: 339 | # server) hostname or IP to connect to 340 | # location) URI in web server 341 | # Return: proxy added to the config file 342 | fastcgi() { local server="$1" location="$2" file=/etc/nginx/conf.d/default.conf 343 | if grep -q "location $location {" $file; then 344 | sed -i '/^[^#]*location '"$(sed 's|/|\\/|g'<<<$location)"' {/,/^ }/c\ 345 | location '"$location"' {\ 346 | }' $file 347 | else 348 | sed -i '/^[^#]*location \/ {$/,/^ }$/ { /^ }/a\ 349 | \ 350 | location '"$location"' {\ 351 | } 352 | }' $file 353 | fi 354 | 355 | sed -i '/^[^#]*location '"$(sed 's|/|\\/|g' <<< $location)"' {/a\ 356 | index index.php;\ 357 | \ 358 | location ~ \.*php {\ 359 | fastcgi_split_path_info ^(.+?\.php)(/.*)$;\ 360 | include fastcgi_params;\ 361 | fastcgi_index index.php;\ 362 | fastcgi_intercept_errors on;\ 363 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\ 364 | fastcgi_param PATH_INFO $fastcgi_path_info;\ 365 | fastcgi_param modHeadersAvailable true;\ 366 | fastcgi_param front_controller_active true;\ 367 | fastcgi_pass '"$server"';\ 368 | \ 369 | ## Optional: Do not log, get it at the destination\ 370 | access_log off;\ 371 | } 372 | ' $file 373 | } 374 | 375 | ### include: incude a configuration file 376 | # Arguments: 377 | # file) to be included 378 | # Return: file included in the config file 379 | include() { local conf="$1" file=/etc/nginx/conf.d/default.conf 380 | grep -q "^[^#]*include $conf;\$" $file || 381 | sed -i '/^[^#]*location \/ /,/^ }/ { /^ }/a\ 382 | \ 383 | include '"$conf"';\ 384 | 385 | }' $file 386 | } 387 | 388 | ### timezone: Set the timezone for the container 389 | # Arguments: 390 | # timezone) for example EST5EDT 391 | # Return: the correct zoneinfo file will be symlinked into place 392 | timezone() { local timezone="${1:-EST5EDT}" 393 | [[ -e /usr/share/zoneinfo/$timezone ]] || { 394 | echo "ERROR: invalid timezone specified: $timezone" >&2 395 | return 396 | } 397 | 398 | if [[ -w /etc/timezone && $(cat /etc/timezone) != $timezone ]]; then 399 | echo "$timezone" >/etc/timezone 400 | ln -sf /usr/share/zoneinfo/$timezone /etc/localtime 401 | dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>&1 402 | fi 403 | } 404 | 405 | ### uwsgi: Configure a UWSGI proxy 406 | # Arguments: 407 | # service) where to contact UWSGI 408 | # location) URI in web server 409 | # Return: UWSGI added to the config file 410 | uwsgi() { local service="$1" location="$2" file=/etc/nginx/conf.d/default.conf 411 | if grep -q "location $location {" $file; then 412 | sed -i '/^[^#]*location '"$(sed 's|/|\\/|g'<<<$location)"' {/,/^ }/c\ 413 | location '"$location"' {\ 414 | }' $file 415 | else 416 | sed -i '/^[^#]*location \/ {$/,/^ }$/ { /^ }/a\ 417 | \ 418 | location '"$location"' {\ 419 | } 420 | }' $file 421 | fi 422 | 423 | sed -i '/^[^#]*location '"$(sed 's|/|\\/|g' <<< $location)"' {/a\ 424 | uwsgi_pass '"$service"';\ 425 | include uwsgi_params;\ 426 | uwsgi_param SCRIPT_NAME '"$location"';\ 427 | uwsgi_modifier1 30;\ 428 | \ 429 | ## Optional: Do not log, get it at the destination\ 430 | access_log off; 431 | ' $file 432 | } 433 | 434 | ### proxy: Configure a web proxy 435 | # Arguments: 436 | # service) where to contact HTTP service 437 | # location) URI in web server 438 | # header) a HTTP header to add as traffic flows through the web proxy 439 | # sockets) set to "no" to disable websockets 440 | # Return: proxy added to the config file 441 | proxy() { local service="$1" location="$2" header="${3:-""}" \ 442 | sockets="${4:-yes}" file=/etc/nginx/conf.d/default.conf 443 | if grep -q "location $location {" $file; then 444 | sed -i '/^[^#]*location '"$(sed 's|/|\\/|g'<<<$location)"' {/,/^ }/c\ 445 | location '"$location"' {\ 446 | }' $file 447 | else 448 | sed -i '/^[^#]*location \/ {$/,/^ }$/ { /^ }/a\ 449 | \ 450 | location '"$location"' {\ 451 | } 452 | }' $file 453 | fi 454 | 455 | sed -i '/^[^#]*location '"$(sed 's|/|\\/|g' <<< $location)"' {/a\ 456 | proxy_pass '"$service"';\ 457 | proxy_set_header Host $http_host;\ 458 | proxy_set_header Range $http_range;\ 459 | proxy_set_header If-Range $http_if_range;\ 460 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\ 461 | proxy_set_header X-Forwarded-Proto $scheme;\ 462 | proxy_set_header X-Real-IP $remote_addr;\ 463 | # Mitigate httpoxy attack (see README for details)\ 464 | proxy_set_header Proxy "";\ 465 | add_header Referrer-Policy "no-referrer";\ 466 | \ 467 | '"$([[ $header ]] && echo -e " proxy_set_header $header;\\\n")"'\ 468 | \ 469 | '"$([[ $sockets != "no" ]] && echo ' ## Required for websockets\ 470 | proxy_http_version 1.1;\ 471 | proxy_set_header Connection "upgrade";\ 472 | proxy_set_header Upgrade $http_upgrade;\ 473 | proxy_read_timeout 3600s;\ 474 | proxy_send_timeout 3600s;')"'\ 475 | \ 476 | ## Optional: Do not log, get it at the destination\ 477 | access_log off; 478 | ' $file 479 | } 480 | 481 | ### proxy_host: Configure a web proxy hostname 482 | # Arguments: 483 | # service) where to contact HTTP service 484 | # hosts) comma separated list of server_name's to listen on 485 | # header) a HTTP header to add as traffic flows through the web proxy 486 | # sockets) set to "no" to disable websockets 487 | # Return: proxy added to the config file 488 | proxy_host() { local service="$1" hosts="$2" header="${3:-""}" \ 489 | sockets="${4:-yes}" file=/etc/nginx/conf.d/default.conf 490 | if grep -q "server { #${hosts%%,*}" $file; then 491 | sed -i '/^[^#]*server { #'"${hosts%%,*}"',/^}/c\ 492 | server { #'"${hosts%%,*}"'\ 493 | }' $file 494 | else 495 | echo -e "\nserver { #${hosts%%,*}\n} #${hosts%%,*}" >>$file 496 | fi 497 | 498 | sed -i '/^server { #'"${hosts%%,*}"'/a\ 499 | listen 443 ssl http2;\ 500 | listen [::]:443 ssl http2;\ 501 | \ 502 | server_name '"$hosts"';\ 503 | \ 504 | ssl_certificate /etc/nginx/ssl/fullchain.pem;\ 505 | ssl_certificate_key /etc/nginx/ssl/privkey.pem;\ 506 | \ 507 | add_header Referrer-Policy "no-referrer";\ 508 | add_header Content-Security-Policy "frame-ancestors '"$(sed 's/,/ /g' <<< \ 509 | $hosts)"'";\ 510 | \ 511 | location / { # '"${hosts%%,*}"'\ 512 | proxy_pass '"$service"';\ 513 | proxy_set_header Host $http_host;\ 514 | proxy_set_header Range $http_range;\ 515 | proxy_set_header If-Range $http_if_range;\ 516 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\ 517 | proxy_set_header X-Forwarded-Proto $scheme;\ 518 | proxy_set_header X-Real-IP $remote_addr;\ 519 | # Mitigate httpoxy attack (see README for details)\ 520 | proxy_set_header Proxy "";\ 521 | '"$([[ $header ]] && echo -e " proxy_set_header $header;\\\n")"'\ 522 | \ 523 | '"$([[ $sockets != "no" ]] && echo ' ## Required for websockets\ 524 | proxy_http_version 1.1;\ 525 | proxy_set_header Connection "upgrade";\ 526 | proxy_set_header Upgrade $http_upgrade;\ 527 | proxy_read_timeout 3600s;\ 528 | proxy_send_timeout 3600s;')"'\ 529 | } # '"${hosts%%,*}"'\ 530 | \ 531 | ## Optional: Do not log, get it at the destination\ 532 | access_log off; 533 | ' $file 534 | } 535 | 536 | ### usage: Help 537 | # Arguments: 538 | # none) 539 | # Return: Help text 540 | usage() { local RC="${1:-0}" 541 | echo "Usage: ${0##*/} [-opt] [command] 542 | Options (fields in '[]' are optional, '<>' are required): 543 | -h This help 544 | -6 Disable IPv6 545 | -B \"[on|off]\" Enables/disables the proxy request buffer, 546 | so that requests are passed through [on/off] (Default on) 547 | -b \"[location][;IP]\" Configure basic auth for \"location\" 548 | possible arg: [location] (defaults to '/') 549 | [location] is the URI in nginx (IE: /wiki) 550 | [;IP] addresses that don't have to authenticate 551 | -C \"\" Configure Content Security Policy header 552 | -c \"\" Configure the client_max_body_size for uploads 553 | -e \"\" Configure EXPIRES header on static assets 554 | possible arg: \"[timeout]\" - timeout for cached files 555 | -f \"\" Configure fastcgi proxy and location 556 | required arg: \";\" 557 | is hostname or IP to connect to 558 | is the URI in nginx (IE: /mediatomb) 559 | -g \"\" Generate a selfsigned SSL cert 560 | possible args: \"[domain][;country][;state][;locality][;org]\" 561 | domain - FQDN for server 562 | country - 2 letter country code 563 | state - state of server location 564 | locality - city 565 | org - company 566 | -P Configure Production mode (no server tokens) 567 | -p \"\" Configure PFS (Perfect Forward Secrecy) 568 | -H Configure HSTS (HTTP Strict Transport Security) 569 | -I \"\" Include a configuration file 570 | required arg: \"\" 571 | to be included 572 | -i Enable SSI (Server Side Includes) 573 | -n set server_name [:oldname] 574 | -q quick (don't create certs) 575 | -R \"\" set header to stop robot indexing 576 | possible arg: \"[tag]\" 577 | all no restrictions (default) 578 | noindex don't show in search results or "Cached" link 579 | nofollow don't follow the links on this page 580 | none equivalent to noindex, nofollow 581 | noarchive don't show a "Cached" link in search results 582 | nosnippet don't show a snippet in the search results 583 | noodp don't use Open Directory project metadata 584 | notranslate don't offer translation of this page 585 | noimageindex don't index images on this page 586 | unavailable_after: [RFC-850 date/time] don't show after 587 | the specified date/time (RFC 850 format) 588 | -r \"\" Redirect a hostname to a URL 589 | required arg: \";\" 590 | to listen for (Fully Qualified Domain Name) 591 | where to send the requests 592 | -S \"\" Configure SSL sessions 593 | possible arg: \"[timeout]\" - timeout for session reuse 594 | -s \"\" Configure SSL stapling 595 | required arg: cert(s) your CA uses for the OCSP check 596 | -T \"[;protocol]\" Configure a stream proxy 597 | required arg: \"<[IP:]port>;\" 598 | what (optional) IP and (required) port to listen on 599 | where to send the requests to : 600 | possible third arg: \"[protocol]\" 601 | [protocol] if not TCP, specify here (IE \"udp\") 602 | -t \"\" Configure timezone 603 | possible arg: \"[timezone]\" - zoneinfo timezone for container 604 | -U \"\" Configure a HTTP auth user 605 | required arg: \"username;password\" 606 | is the name the user enters for authorization 607 | is the password the user enters for authorization 608 | -u \"\" Configure UWSGI proxy and location 609 | required arg: \";\" 610 | is how to contact UWSGI 611 | is the URI in nginx (IE: /wiki) 612 | -W \"\" Configure web proxy hostname and location 613 | required arg: \"http:///;hosts\" 614 | is how to contact the HTTP service 615 | is a comma separated list of host names (minimum of 1) 616 | **NOTE**: the webserver will listen, but DNS is still needed 617 | possible args: \"[header value]\" \"[sockets]\" 618 | [header value] set \"header\" to \"value\" on traffic going 619 | through the proxy 620 | [sockets] if set to \"no\" don't enable use of websockets 621 | -w \"\" Configure web proxy and location 622 | required arg: \"http:///;//\" 623 | is how to contact the HTTP service 624 | is the URI in nginx (IE: /mediatomb) 625 | possible args: \"[header value]\" \"[sockets]\" 626 | [header value] set \"header\" to \"value\" on traffic going 627 | through the proxy 628 | [sockets] if set to \"no\" don't enable use of websockets 629 | 630 | The 'command' (if provided and valid) will be run instead of nginx 631 | " >&2 632 | exit $RC 633 | } 634 | 635 | while getopts ":h6B:b:C:c:g:e:f:PpHI:in:R:r:S:s:T:t:U:u:W:w:q" opt; do 636 | case "$opt" in 637 | h) usage ;; 638 | 6) ipv6 ;; 639 | B) proxy_request_buffering "$OPTARG" ;; 640 | b) eval basic $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 641 | C) content_security "$OPTARG" ;; 642 | c) client_max_body_size "$OPTARG" ;; 643 | g) eval gencert $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 644 | e) static $OPTARG ;; 645 | f) eval fastcgi $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 646 | P) prod ;; 647 | p) pfs ;; 648 | H) hsts ;; 649 | I) include "$OPTARG" ;; 650 | i) ssi ;; 651 | n) eval name $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 652 | q) quick=1 ;; 653 | R) robot "$OPTARG" ;; 654 | r) eval redirect $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 655 | S) ssl_sessions $OPTARG ;; 656 | s) stapling $OPTARG ;; 657 | T) eval stream $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 658 | t) timezone $OPTARG ;; 659 | U) eval http_user $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 660 | u) eval uwsgi $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 661 | W) eval proxy_host $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 662 | w) eval proxy $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $OPTARG) ;; 663 | "?") echo "Unknown option: -$OPTARG"; usage 1 ;; 664 | ":") echo "No argument value for option: -$OPTARG"; usage 2 ;; 665 | esac 666 | done 667 | shift $(( OPTIND - 1 )) 668 | 669 | [[ "${IPV6:-""}" ]] && ipv6 670 | [[ "${BASIC:-""}" ]] && eval basic $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< \ 671 | $BASIC) 672 | [[ "${GENCERT:-""}" ]] && eval gencert $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< \ 673 | $GENCERT) 674 | [[ "${EXPIRES:-""}" ]] && ssl_sessions $EXPIRES 675 | [[ "${FASTCGI:-""}" ]] && eval fastcgi $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< \ 676 | $FASTCGI) 677 | [[ "${PFS:-""}" ]] && pfs 678 | [[ "${PROD:-""}" ]] && prod 679 | [[ "${HSTS:-""}" ]] && hsts 680 | [[ "${INCLUDE:-""}" ]] && include "$INCLUDE" 681 | [[ "${SSI:-""}" ]] && ssi 682 | [[ "${STREAM:-""}" ]] && eval stream $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< \ 683 | $STREAM) 684 | [[ "${NAME:-""}" ]] && eval name $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< $NAME) 685 | [[ "${OUICK:-""}" ]] && quick=1 686 | [[ "${REDIRECT:-""}" ]] && eval redirect $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' \ 687 | <<< $REDIRECT) 688 | [[ "${ROBOT:-""}" ]] && robot "$ROBOT" 689 | [[ "${STAPLING:-""}" ]] && stapling $STAPLING 690 | [[ "${SSL_SESSIONS:-""}" ]] && ssl_sessions $SSL_SESSIONS 691 | [[ "${TZ:-""}" ]] && timezone $TZ 692 | while read i; do 693 | eval http_user $(sed 's/^/"/; s/$/"/; s/;/" "/g' <<< $i) 694 | done < <(env | awk '/^HTTPUSER[0-9=_]/ {sub (/^[^=]*=/, "", $0); print}') 695 | [[ "${UWSGI:-""}" ]] && eval uwsgi $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< \ 696 | $UWSGI) 697 | [[ "${PROXY:-""}" ]] && eval proxy $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< \ 698 | $PROXY) 699 | [[ "${PROXYHOST:-""}" ]] && eval proxy $(sed 's/^/"/g; s/$/"/g; s/;/" "/g' <<< \ 700 | $PROXYHOST) 701 | [[ "${PROXYBUFFER:-""}" ]] && proxy_request_buffering "$PROXYBUFFER" 702 | [[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o nginx 703 | [[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o nginx 704 | [[ "${CONTENTSECURITY:-""}" ]] && content_security "$CONTENTSECURITY" 705 | [[ "${CLIENTMAXBODYSIZE:-""}" ]] && client_max_body_size "$CLIENTMAXBODYSIZE" 706 | 707 | [[ -d /var/cache/nginx/cache ]] || mkdir -p /var/cache/nginx/cache 708 | chown -Rh nginx. /var/cache/nginx 2>&1 | grep -iv 'Read-only' || : 709 | [[ -d /etc/nginx/ssl || ${quick:-""} ]] || gencert 710 | [[ -e /etc/nginx/conf.d/sessions.conf ]] || ssl_sessions 711 | [[ ! -e /etc/nginx/ssl/chain.pem && -e /etc/nginx/ssl/ocsp.pem ]] && 712 | sed -i 's|chain\.pem|ocsp.pem|' /etc/nginx/conf.d/stapling.conf 713 | [[ ! -e /etc/nginx/ssl/fullchain.pem && -e /etc/nginx/ssl/cert.pem ]] && 714 | sed -i 's|fullchain\.pem|cert.pem|' /etc/nginx/conf.d/default.conf 715 | [[ ! -e /etc/nginx/ssl/privkey.pem && -e /etc/nginx/ssl/key.pem ]] && 716 | sed -i 's|privkey\.pem|key.pem|' /etc/nginx/conf.d/default.conf 717 | 718 | if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then 719 | exec "$@" 720 | elif [[ $# -ge 1 ]]; then 721 | echo "ERROR: command not found: $1" 722 | exit 13 723 | elif ps -ef | egrep -v 'grep|nginx.sh' | grep -q nginx; then 724 | echo "Service already running, please restart container to apply changes" 725 | else 726 | exec nginx -g "daemon off;" 727 | fi --------------------------------------------------------------------------------