├── .gitignore ├── LICENSE ├── README.md ├── appveyor.yml ├── appveyor_build.bat ├── nginx-0001-install-allow-empty-prefix.patch ├── nginx-0002-win32-force-utf-8-encoding-in-ngx_dir_t.patch ├── nginx-0003-ngx_files-implement-some-functions-in-utf8-encoding.patch ├── nginx-0004-ngx_files-implement-ngx_open_tempfile-in-utf8-encodi.patch ├── nginx-0005-ngx_files-implement-ngx_open_glob-and-ngx_read_glob-.patch ├── nginx-0006-ngx_files-implement-ngx_win32_rename_file-in-utf8-en.patch ├── nginx-0007-logs-write-access-log-to-stderr.patch ├── nginx-build-msys2.sh └── nginx-package-msys2.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Packages 2 | *.gz 3 | *.bz2 4 | *.xz 5 | *.7z 6 | *.tar 7 | 8 | # Source folders 9 | nginx/* 10 | openssl-*/* 11 | libressl-*/* 12 | pcre-*/* 13 | zlib-*/* 14 | conf/* 15 | contrib/* 16 | docs/* 17 | html/* 18 | logs/* 19 | temp/* 20 | 21 | # Prerequisites 22 | *.d 23 | 24 | # Object files 25 | *.o 26 | *.ko 27 | *.obj 28 | *.elf 29 | 30 | # Linker output 31 | *.ilk 32 | *.map 33 | *.exp 34 | 35 | # Precompiled Headers 36 | *.gch 37 | *.pch 38 | 39 | # Libraries 40 | *.lib 41 | *.a 42 | *.la 43 | *.lo 44 | 45 | # Shared objects (inc. Windows DLLs) 46 | *.dll 47 | *.so 48 | *.so.* 49 | *.dylib 50 | 51 | # Executables 52 | *.exe 53 | *.out 54 | *.app 55 | *.i*86 56 | *.x86_64 57 | *.hex 58 | 59 | # Debug files 60 | *.dSYM/ 61 | *.su 62 | *.idb 63 | *.pdb 64 | 65 | # Kernel Module Compile Results 66 | *.mod* 67 | *.cmd 68 | .tmp_versions/ 69 | modules.order 70 | Module.symvers 71 | Mkfile.old 72 | dkms.conf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2018, myfreeer 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nginx-build-msys2 2 | 3 | nginx build scripts on msys2 mingw with dependencies and custom patches 4 | 5 | ## Badges 6 | 7 | [![Build status](https://ci.appveyor.com/api/projects/status/cjd77mirpuc5leht?svg=true)](https://ci.appveyor.com/project/myfreeer/nginx-build-msys2) 8 | 9 | ## Features 10 | 11 | * native x86-64 (x64, amd64) build for windows. 12 | * nginx can execute in directory or path containing non-ascii characters. (Not needed since [1.23.4](https://github.com/nginx/nginx/commits/release-1.23.4/src/os/win32)) 13 | * read file names in directory as utf8 encoding (affecting autoindex module). (Not needed since [1.23.4](https://github.com/nginx/nginx/commits/release-1.23.4/src/os/win32)) 14 | 15 | ## [Releases](https://github.com/myfreeer/nginx-build-msys2/releases) 16 | 17 | * `nginx-*-i686.exe`: 32-bit nginx 18 | * `nginx-*-i686-debug.exe`: 32-bit nginx with debugging log and symbols 19 | * `nginx-*-x86_64.exe`: 64-bit nginx 20 | * `nginx-*-x86_64-debug.exe`: 64-bit nginx with debugging log and symbols 21 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | build_script: 3 | - cmd: >- 4 | appveyor_build.bat 5 | shallow_clone: true 6 | test: off 7 | artifacts: 8 | - path: nginx-bin.7z 9 | skip_commits: 10 | files: 11 | - 'LICENSE' 12 | - '*.md' 13 | - '.gitingore' 14 | deploy: 15 | - provider: Environment 16 | name: github 17 | on: 18 | appveyor_repo_tag: true -------------------------------------------------------------------------------- /appveyor_build.bat: -------------------------------------------------------------------------------- 1 | set cmdLine="cd \"$APPVEYOR_BUILD_FOLDER\" && exec ./nginx-build-msys2.sh" 2 | if "%APPVEYOR_REPO_TAG%" == "true" set cmdLine="cd \"$APPVEYOR_BUILD_FOLDER\" && exec ./nginx-build-msys2.sh --tag=release-$APPVEYOR_REPO_TAG_NAME" 3 | 4 | set MSYSTEM=MINGW64 5 | C:\msys64\usr\bin\bash -lc %cmdLine% 6 | set MSYSTEM=MINGW32 7 | C:\msys64\usr\bin\bash -lc %cmdLine% 8 | 9 | C:\msys64\usr\bin\bash -lc "cd \"$APPVEYOR_BUILD_FOLDER\" && exec ./nginx-package-msys2.sh" -------------------------------------------------------------------------------- /nginx-0001-install-allow-empty-prefix.patch: -------------------------------------------------------------------------------- 1 | From 7094ee0c174c37d0b9f6f409b08dfd6f1ec39ea9 Mon Sep 17 00:00:00 2001 2 | From: myfreeer 3 | Date: Fri, 20 Jul 2018 09:39:30 +0800 4 | Subject: [PATCH] install: allow prefix with relative path 5 | 6 | --- 7 | auto/install | 18 ++++++++++++------ 8 | 1 file changed, 12 insertions(+), 6 deletions(-) 9 | 10 | diff --git a/auto/install b/auto/install 11 | index d884487..5935a70 100644 12 | --- a/auto/install 13 | +++ b/auto/install 14 | @@ -16,12 +16,18 @@ END 15 | fi 16 | 17 | 18 | +if [ "${NGX_PREFIX}" == "" ]; then 19 | + NGX_PREFIX_PATH="" 20 | +else 21 | + NGX_PREFIX_PATH="${NGX_PREFIX}/" 22 | +fi 23 | + 24 | case ".$NGX_SBIN_PATH" in 25 | ./*) 26 | ;; 27 | 28 | *) 29 | - NGX_SBIN_PATH=$NGX_PREFIX/$NGX_SBIN_PATH 30 | + NGX_SBIN_PATH=${NGX_PREFIX_PATH}$NGX_SBIN_PATH 31 | ;; 32 | esac 33 | 34 | @@ -31,7 +37,7 @@ case ".$NGX_MODULES_PATH" in 35 | ;; 36 | 37 | *) 38 | - NGX_MODULES_PATH=$NGX_PREFIX/$NGX_MODULES_PATH 39 | + NGX_MODULES_PATH=${NGX_PREFIX_PATH}$NGX_MODULES_PATH 40 | ;; 41 | esac 42 | 43 | @@ -43,7 +49,7 @@ case ".$NGX_CONF_PATH" in 44 | ;; 45 | 46 | *) 47 | - NGX_CONF_PATH=$NGX_PREFIX/$NGX_CONF_PATH 48 | + NGX_CONF_PATH=${NGX_PREFIX_PATH}$NGX_CONF_PATH 49 | ;; 50 | esac 51 | 52 | @@ -56,7 +62,7 @@ case ".$NGX_PID_PATH" in 53 | ;; 54 | 55 | *) 56 | - NGX_PID_PATH=$NGX_PREFIX/$NGX_PID_PATH 57 | + NGX_PID_PATH=${NGX_PREFIX_PATH}$NGX_PID_PATH 58 | ;; 59 | esac 60 | 61 | @@ -66,7 +72,7 @@ case ".$NGX_ERROR_LOG_PATH" in 62 | ;; 63 | 64 | *) 65 | - NGX_ERROR_LOG_PATH=$NGX_PREFIX/$NGX_ERROR_LOG_PATH 66 | + NGX_ERROR_LOG_PATH=${NGX_PREFIX_PATH}$NGX_ERROR_LOG_PATH 67 | ;; 68 | esac 69 | 70 | @@ -76,7 +82,7 @@ case ".$NGX_HTTP_LOG_PATH" in 71 | ;; 72 | 73 | *) 74 | - NGX_HTTP_LOG_PATH=$NGX_PREFIX/$NGX_HTTP_LOG_PATH 75 | + NGX_HTTP_LOG_PATH=${NGX_PREFIX_PATH}$NGX_HTTP_LOG_PATH 76 | ;; 77 | esac 78 | 79 | -- 80 | 2.18.0 81 | 82 | -------------------------------------------------------------------------------- /nginx-0002-win32-force-utf-8-encoding-in-ngx_dir_t.patch: -------------------------------------------------------------------------------- 1 | From 3e6a8cbee0f585286940120a0e3feec9fe3bad7a Mon Sep 17 00:00:00 2001 2 | From: myfreeer 3 | Date: Sun, 30 Dec 2018 20:40:21 +0800 4 | Subject: [PATCH] win32: force utf-8 encoding in ngx_dir_t 5 | 6 | --- 7 | src/os/win32/ngx_files.c | 27 ++++++++++++++++++++++----- 8 | src/os/win32/ngx_files.h | 8 +++++--- 9 | 2 files changed, 27 insertions(+), 8 deletions(-) 10 | 11 | diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c 12 | index 0b131b5..f2d07e1 100644 13 | --- a/src/os/win32/ngx_files.c 14 | +++ b/src/os/win32/ngx_files.c 15 | @@ -429,6 +429,9 @@ ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) 16 | { 17 | u_char *pattern, *p; 18 | ngx_err_t err; 19 | + size_t len; 20 | + u_short *u; 21 | + u_short utf16[NGX_UTF16_BUFLEN]; 22 | 23 | pattern = malloc(name->len + 3); 24 | if (pattern == NULL) { 25 | @@ -436,21 +439,30 @@ ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) 26 | } 27 | 28 | p = ngx_cpymem(pattern, name->data, name->len); 29 | - 30 | *p++ = '/'; 31 | *p++ = '*'; 32 | *p = '\0'; 33 | 34 | - dir->dir = FindFirstFile((const char *) pattern, &dir->finddata); 35 | + len = NGX_UTF16_BUFLEN; 36 | + u = ngx_utf8_to_utf16(utf16, pattern, &len); 37 | + ngx_free(pattern); 38 | + if (u == NULL) { 39 | + return NGX_ERROR; 40 | + } 41 | 42 | + dir->dir = FindFirstFileW((LPCWSTR) u, &dir->finddata); 43 | + if (u != utf16) { 44 | + ngx_free(u); 45 | + } 46 | if (dir->dir == INVALID_HANDLE_VALUE) { 47 | err = ngx_errno; 48 | - ngx_free(pattern); 49 | ngx_set_errno(err); 50 | return NGX_ERROR; 51 | } 52 | 53 | - ngx_free(pattern); 54 | + dir->utf8_length = WideCharToMultiByte(CP_UTF8, 0, dir->finddata.cFileName, -1, NULL, 0, NULL, NULL); 55 | + dir->utf8 = calloc(dir->utf8_length, sizeof(char)); 56 | + WideCharToMultiByte(CP_UTF8, 0, dir->finddata.cFileName, -1, dir->utf8, dir->utf8_length, NULL, NULL); 57 | 58 | dir->valid_info = 1; 59 | dir->ready = 1; 60 | @@ -467,8 +479,12 @@ ngx_read_dir(ngx_dir_t *dir) 61 | return NGX_OK; 62 | } 63 | 64 | - if (FindNextFile(dir->dir, &dir->finddata) != 0) { 65 | + if (FindNextFileW(dir->dir, &dir->finddata) != 0) { 66 | dir->type = 1; 67 | + free(dir->utf8); 68 | + dir->utf8_length = WideCharToMultiByte(CP_UTF8, 0, dir->finddata.cFileName, -1, NULL, 0, NULL, NULL); 69 | + dir->utf8 = calloc(dir->utf8_length, sizeof(char)); 70 | + WideCharToMultiByte(CP_UTF8, 0, dir->finddata.cFileName, -1, dir->utf8, dir->utf8_length, NULL, NULL); 71 | return NGX_OK; 72 | } 73 | 74 | @@ -479,6 +495,7 @@ ngx_read_dir(ngx_dir_t *dir) 75 | ngx_int_t 76 | ngx_close_dir(ngx_dir_t *dir) 77 | { 78 | + free(dir->utf8); 79 | if (FindClose(dir->dir) == 0) { 80 | return NGX_ERROR; 81 | } 82 | diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h 83 | index 6eb720e..57bfe7e 100644 84 | --- a/src/os/win32/ngx_files.h 85 | +++ b/src/os/win32/ngx_files.h 86 | @@ -30,7 +30,9 @@ typedef struct { 87 | 88 | typedef struct { 89 | HANDLE dir; 90 | - WIN32_FIND_DATA finddata; 91 | + WIN32_FIND_DATAW finddata; 92 | + char* utf8; 93 | + int utf8_length; 94 | 95 | unsigned valid_info:1; 96 | unsigned type:1; 97 | @@ -205,8 +207,8 @@ ngx_int_t ngx_close_dir(ngx_dir_t *dir); 98 | #define ngx_dir_access(a) (a) 99 | 100 | 101 | -#define ngx_de_name(dir) ((u_char *) (dir)->finddata.cFileName) 102 | -#define ngx_de_namelen(dir) ngx_strlen((dir)->finddata.cFileName) 103 | +#define ngx_de_name(dir) ((u_char *) (dir)->utf8) 104 | +#define ngx_de_namelen(dir) ((dir)->utf8_length - 1) 105 | 106 | ngx_int_t ngx_de_info(u_char *name, ngx_dir_t *dir); 107 | #define ngx_de_info_n "dummy()" 108 | -- 109 | 2.19.1 110 | 111 | -------------------------------------------------------------------------------- /nginx-0003-ngx_files-implement-some-functions-in-utf8-encoding.patch: -------------------------------------------------------------------------------- 1 | From 83460b316515224c0d35f69ba9cd330c22772e3e Mon Sep 17 00:00:00 2001 2 | From: myfreeer 3 | Date: Mon, 4 Nov 2019 21:44:10 +0800 4 | Subject: [PATCH] ngx_files: implement some functions in utf8 encoding 5 | 6 | * ngx_getcwd 7 | * ngx_create_dir 8 | * ngx_delete_dir 9 | * ngx_delete_file 10 | * ngx_rename_file 11 | 12 | nginx would initially run in non-ascii dir. 13 | --- 14 | src/os/win32/ngx_files.c | 140 +++++++++++++++++++++++++++++++++++++++ 15 | src/os/win32/ngx_files.h | 24 +++---- 16 | 2 files changed, 150 insertions(+), 14 deletions(-) 17 | 18 | diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c 19 | index f2d07e1..fc69e6d 100644 20 | --- a/src/os/win32/ngx_files.c 21 | +++ b/src/os/win32/ngx_files.c 22 | @@ -301,6 +301,146 @@ failed: 23 | return rc; 24 | } 25 | 26 | +ngx_int_t 27 | +ngx_getcwd(u_char *buf, ngx_int_t size) 28 | +{ 29 | + WCHAR wBuffer[NGX_MAX_PATH]; 30 | + ngx_int_t ret = GetCurrentDirectoryW(NGX_MAX_PATH, wBuffer); 31 | + if (ret == 0) { 32 | + return 0; 33 | + } 34 | + return WideCharToMultiByte(CP_UTF8, 0, wBuffer, -1, (char *) buf, size, NULL, NULL); 35 | +} 36 | + 37 | +ngx_int_t 38 | +ngx_create_dir(u_char *name, ngx_int_t access) 39 | +{ 40 | + size_t len; 41 | + long rc; 42 | + u_short *u; 43 | + ngx_err_t err; 44 | + u_short utf16[NGX_UTF16_BUFLEN]; 45 | + 46 | + len = NGX_UTF16_BUFLEN; 47 | + 48 | + u = ngx_utf8_to_utf16(utf16, name, &len); 49 | + 50 | + if (u == NULL) { 51 | + return NGX_FILE_ERROR; 52 | + } 53 | + 54 | + rc = CreateDirectoryW((const WCHAR *)u, NULL); 55 | + 56 | + if (u != utf16) { 57 | + err = ngx_errno; 58 | + ngx_free(u); 59 | + ngx_set_errno(err); 60 | + } 61 | + 62 | + return rc; 63 | +} 64 | + 65 | +ngx_int_t 66 | +ngx_delete_dir(u_char *name) 67 | +{ 68 | + size_t len; 69 | + long rc; 70 | + u_short *u; 71 | + ngx_err_t err; 72 | + u_short utf16[NGX_UTF16_BUFLEN]; 73 | + 74 | + len = NGX_UTF16_BUFLEN; 75 | + 76 | + u = ngx_utf8_to_utf16(utf16, name, &len); 77 | + 78 | + if (u == NULL) { 79 | + return NGX_FILE_ERROR; 80 | + } 81 | + 82 | + rc = RemoveDirectoryW((const WCHAR *)u); 83 | + 84 | + if (u != utf16) { 85 | + err = ngx_errno; 86 | + ngx_free(u); 87 | + ngx_set_errno(err); 88 | + } 89 | + 90 | + return rc; 91 | +} 92 | + 93 | +ngx_int_t 94 | +ngx_delete_file(u_char *name) 95 | +{ 96 | + size_t len; 97 | + long rc; 98 | + u_short *u; 99 | + ngx_err_t err; 100 | + u_short utf16[NGX_UTF16_BUFLEN]; 101 | + 102 | + len = NGX_UTF16_BUFLEN; 103 | + 104 | + u = ngx_utf8_to_utf16(utf16, name, &len); 105 | + 106 | + if (u == NULL) { 107 | + return NGX_FILE_ERROR; 108 | + } 109 | + 110 | + rc = DeleteFileW((const WCHAR *)u); 111 | + 112 | + if (u != utf16) { 113 | + err = ngx_errno; 114 | + ngx_free(u); 115 | + ngx_set_errno(err); 116 | + } 117 | + 118 | + return rc; 119 | +} 120 | + 121 | +ngx_int_t 122 | +ngx_rename_file(u_char *o, u_char *n) 123 | +{ 124 | + size_t len1; 125 | + size_t len2; 126 | + long rc; 127 | + u_short *u1; 128 | + u_short *u2; 129 | + ngx_err_t err; 130 | + u_short utf16_1[NGX_UTF16_BUFLEN]; 131 | + u_short utf16_2[NGX_UTF16_BUFLEN]; 132 | + 133 | + len1 = NGX_UTF16_BUFLEN; 134 | + len2 = NGX_UTF16_BUFLEN; 135 | + 136 | + u1 = ngx_utf8_to_utf16(utf16_1, o, &len1); 137 | + 138 | + if (u1 == NULL) { 139 | + return NGX_FILE_ERROR; 140 | + } 141 | + 142 | + rc = NGX_FILE_ERROR; 143 | + u2 = ngx_utf8_to_utf16(utf16_2, n, &len2); 144 | + 145 | + if (u2 == NULL) { 146 | + goto fail1; 147 | + } 148 | + 149 | + rc = MoveFileW((const WCHAR *) u1, (const WCHAR *) u2); 150 | + 151 | + if (u2 != utf16_2) { 152 | + err = ngx_errno; 153 | + ngx_free(u2); 154 | + ngx_set_errno(err); 155 | + } 156 | + 157 | +fail1: 158 | + if (u1 != utf16_1) { 159 | + err = ngx_errno; 160 | + ngx_free(u1); 161 | + ngx_set_errno(err); 162 | + } 163 | + 164 | + return rc; 165 | +} 166 | 167 | ngx_int_t 168 | ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) 169 | diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h 170 | index 57bfe7e..441a9a1 100644 171 | --- a/src/os/win32/ngx_files.h 172 | +++ b/src/os/win32/ngx_files.h 173 | @@ -120,13 +120,11 @@ ssize_t ngx_write_console(ngx_fd_t fd, void *buf, size_t size); 174 | #define NGX_LINEFEED_SIZE 2 175 | #define NGX_LINEFEED CRLF 176 | 177 | +ngx_int_t ngx_delete_file(u_char *name); 178 | +#define ngx_delete_file_n "DeleteFileW()" 179 | 180 | -#define ngx_delete_file(name) DeleteFile((const char *) name) 181 | -#define ngx_delete_file_n "DeleteFile()" 182 | - 183 | - 184 | -#define ngx_rename_file(o, n) MoveFile((const char *) o, (const char *) n) 185 | -#define ngx_rename_file_n "MoveFile()" 186 | +ngx_int_t ngx_rename_file(u_char *o, u_char *n); 187 | +#define ngx_rename_file_n "MoveFileW()" 188 | ngx_err_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log); 189 | 190 | 191 | @@ -176,8 +174,8 @@ void ngx_close_file_mapping(ngx_file_mapping_t *fm); 192 | 193 | u_char *ngx_realpath(u_char *path, u_char *resolved); 194 | #define ngx_realpath_n "" 195 | -#define ngx_getcwd(buf, size) GetCurrentDirectory(size, (char *) buf) 196 | -#define ngx_getcwd_n "GetCurrentDirectory()" 197 | +ngx_int_t ngx_getcwd(u_char *buf, ngx_int_t size); 198 | +#define ngx_getcwd_n "GetCurrentDirectoryW()" 199 | #define ngx_path_separator(c) ((c) == '/' || (c) == '\\') 200 | 201 | #define NGX_HAVE_MAX_PATH 1 202 | @@ -195,13 +193,11 @@ ngx_int_t ngx_read_dir(ngx_dir_t *dir); 203 | ngx_int_t ngx_close_dir(ngx_dir_t *dir); 204 | #define ngx_close_dir_n "FindClose()" 205 | 206 | +ngx_int_t ngx_create_dir(u_char *name, ngx_int_t access); 207 | +#define ngx_create_dir_n "CreateDirectoryW()" 208 | 209 | -#define ngx_create_dir(name, access) CreateDirectory((const char *) name, NULL) 210 | -#define ngx_create_dir_n "CreateDirectory()" 211 | - 212 | - 213 | -#define ngx_delete_dir(name) RemoveDirectory((const char *) name) 214 | -#define ngx_delete_dir_n "RemoveDirectory()" 215 | +ngx_int_t ngx_delete_dir(u_char *name); 216 | +#define ngx_delete_dir_n "RemoveDirectoryW()" 217 | 218 | 219 | #define ngx_dir_access(a) (a) 220 | -- 221 | 2.23.0 222 | 223 | -------------------------------------------------------------------------------- /nginx-0004-ngx_files-implement-ngx_open_tempfile-in-utf8-encodi.patch: -------------------------------------------------------------------------------- 1 | From 34f9aca0bdd33867ee55b736d78006460310a9ed Mon Sep 17 00:00:00 2001 2 | From: myfreeer 3 | Date: Tue, 5 Nov 2019 19:54:45 +0800 4 | Subject: [PATCH 1/3] ngx_files: implement ngx_open_tempfile in utf8 encoding 5 | 6 | --- 7 | src/os/win32/ngx_files.c | 35 ++++++++++++++++++++++++++++++++++- 8 | src/os/win32/ngx_files.h | 11 ++--------- 9 | 2 files changed, 36 insertions(+), 10 deletions(-) 10 | 11 | diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c 12 | index fc69e6d..0ed27bb 100644 13 | --- a/src/os/win32/ngx_files.c 14 | +++ b/src/os/win32/ngx_files.c 15 | @@ -15,6 +15,39 @@ static ngx_int_t ngx_win32_check_filename(u_char *name, u_short *u, 16 | size_t len); 17 | static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len); 18 | 19 | +ngx_fd_t 20 | +ngx_open_tempfile(u_char *name, ngx_uint_t persistent, ngx_uint_t access) 21 | +{ 22 | + 23 | + size_t len; 24 | + u_short *u; 25 | + ngx_fd_t fd; 26 | + ngx_err_t err; 27 | + u_short utf16[NGX_UTF16_BUFLEN]; 28 | + 29 | + len = NGX_UTF16_BUFLEN; 30 | + u = ngx_utf8_to_utf16(utf16, name, &len); 31 | + 32 | + if (u == NULL) { 33 | + return INVALID_HANDLE_VALUE; 34 | + } 35 | + 36 | + fd = CreateFileW(u, GENERIC_READ|GENERIC_WRITE, 37 | + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 38 | + NULL, 39 | + CREATE_NEW, 40 | + persistent ? 0 : 41 | + FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE, 42 | + NULL); 43 | + 44 | + if (u != utf16) { 45 | + err = ngx_errno; 46 | + ngx_free(u); 47 | + ngx_set_errno(err); 48 | + } 49 | + 50 | + return fd; 51 | +} 52 | 53 | /* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */ 54 | 55 | @@ -494,7 +527,7 @@ ngx_create_file_mapping(ngx_file_mapping_t *fm) 56 | goto failed; 57 | } 58 | 59 | - fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE, 60 | + fm->handle = CreateFileMappingW(fm->fd, NULL, PAGE_READWRITE, 61 | (u_long) ((off_t) fm->size >> 32), 62 | (u_long) ((off_t) fm->size & 0xffffffff), 63 | NULL); 64 | diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h 65 | index 441a9a1..6a6aa25 100644 66 | --- a/src/os/win32/ngx_files.h 67 | +++ b/src/os/win32/ngx_files.h 68 | @@ -88,15 +88,8 @@ ngx_fd_t ngx_open_file(u_char *name, u_long mode, u_long create, u_long access); 69 | #define NGX_FILE_OWNER_ACCESS 0 70 | 71 | 72 | -#define ngx_open_tempfile(name, persistent, access) \ 73 | - CreateFile((const char *) name, \ 74 | - GENERIC_READ|GENERIC_WRITE, \ 75 | - FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, \ 76 | - NULL, \ 77 | - CREATE_NEW, \ 78 | - persistent ? 0: \ 79 | - FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE, \ 80 | - NULL); 81 | +ngx_fd_t ngx_open_tempfile(u_char *name, ngx_uint_t persistent, 82 | + ngx_uint_t access); 83 | 84 | #define ngx_open_tempfile_n "CreateFile()" 85 | 86 | -- 87 | 2.23.0 88 | 89 | -------------------------------------------------------------------------------- /nginx-0005-ngx_files-implement-ngx_open_glob-and-ngx_read_glob-.patch: -------------------------------------------------------------------------------- 1 | From 95e5e4c05f8e3d2f643fa65011c5b3527746af0b Mon Sep 17 00:00:00 2001 2 | From: myfreeer 3 | Date: Tue, 5 Nov 2019 20:42:09 +0800 4 | Subject: [PATCH 2/3] ngx_files: implement ngx_open_glob and ngx_read_glob in 5 | utf8 encoding 6 | 7 | include would work in non-ascii path on win32 8 | --- 9 | src/os/win32/ngx_files.c | 46 +++++++++++++++++++++++++++++----------- 10 | src/os/win32/ngx_files.h | 2 +- 11 | 2 files changed, 35 insertions(+), 13 deletions(-) 12 | 13 | diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c 14 | index 0ed27bb..fb413f2 100644 15 | --- a/src/os/win32/ngx_files.c 16 | +++ b/src/os/win32/ngx_files.c 17 | @@ -680,11 +680,20 @@ ngx_close_dir(ngx_dir_t *dir) 18 | ngx_int_t 19 | ngx_open_glob(ngx_glob_t *gl) 20 | { 21 | + ngx_int_t rc; 22 | u_char *p; 23 | size_t len; 24 | ngx_err_t err; 25 | + u_short *u; 26 | + u_short utf16[NGX_UTF16_BUFLEN]; 27 | + 28 | + len = NGX_UTF16_BUFLEN; 29 | + u = ngx_utf8_to_utf16(utf16, gl->pattern, &len); 30 | + if (u == NULL) { 31 | + return NGX_ERROR; 32 | + } 33 | 34 | - gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata); 35 | + gl->dir = FindFirstFileW((LPCWSTR) u, &gl->finddata); 36 | 37 | if (gl->dir == INVALID_HANDLE_VALUE) { 38 | 39 | @@ -694,10 +703,12 @@ ngx_open_glob(ngx_glob_t *gl) 40 | && gl->test) 41 | { 42 | gl->no_match = 1; 43 | - return NGX_OK; 44 | + rc = NGX_OK; 45 | + goto failed; 46 | } 47 | 48 | - return NGX_ERROR; 49 | + rc = NGX_ERROR; 50 | + goto failed; 51 | } 52 | 53 | for (p = gl->pattern; *p; p++) { 54 | @@ -706,21 +717,30 @@ ngx_open_glob(ngx_glob_t *gl) 55 | } 56 | } 57 | 58 | - len = ngx_strlen(gl->finddata.cFileName); 59 | + len = WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1, NULL, 0, NULL, NULL); 60 | gl->name.len = gl->last + len; 61 | 62 | gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); 63 | if (gl->name.data == NULL) { 64 | - return NGX_ERROR; 65 | + rc = NGX_ERROR; 66 | + goto failed; 67 | } 68 | 69 | ngx_memcpy(gl->name.data, gl->pattern, gl->last); 70 | - ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, 71 | - len + 1); 72 | + WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1, 73 | + (char *) gl->name.data + gl->last, len, NULL, NULL); 74 | + gl->name.data[gl->name.len] = '\0'; 75 | 76 | gl->ready = 1; 77 | + rc = NGX_OK; 78 | 79 | - return NGX_OK; 80 | +failed: 81 | + if (u != utf16) { 82 | + err = ngx_errno; 83 | + ngx_free(u); 84 | + ngx_set_errno(err); 85 | + } 86 | + return rc; 87 | } 88 | 89 | 90 | @@ -744,9 +764,9 @@ ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) 91 | ngx_free(gl->name.data); 92 | gl->name.data = NULL; 93 | 94 | - if (FindNextFile(gl->dir, &gl->finddata) != 0) { 95 | + if (FindNextFileW(gl->dir, &gl->finddata) != 0) { 96 | 97 | - len = ngx_strlen(gl->finddata.cFileName); 98 | + len = WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1, NULL, 0, NULL, NULL); 99 | gl->name.len = gl->last + len; 100 | 101 | gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); 102 | @@ -755,8 +775,10 @@ ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) 103 | } 104 | 105 | ngx_memcpy(gl->name.data, gl->pattern, gl->last); 106 | - ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, 107 | - len + 1); 108 | + 109 | + WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1, 110 | + (char *) gl->name.data + gl->last, len, NULL, NULL); 111 | + gl->name.data[gl->name.len] = '\0'; 112 | 113 | *name = gl->name; 114 | 115 | diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h 116 | index 6a6aa25..01e64a0 100644 117 | --- a/src/os/win32/ngx_files.h 118 | +++ b/src/os/win32/ngx_files.h 119 | @@ -42,7 +42,7 @@ typedef struct { 120 | 121 | typedef struct { 122 | HANDLE dir; 123 | - WIN32_FIND_DATA finddata; 124 | + WIN32_FIND_DATAW finddata; 125 | 126 | unsigned ready:1; 127 | unsigned test:1; 128 | -- 129 | 2.23.0 130 | 131 | -------------------------------------------------------------------------------- /nginx-0006-ngx_files-implement-ngx_win32_rename_file-in-utf8-en.patch: -------------------------------------------------------------------------------- 1 | From d692adb4a34324839176d31009b98f26a67e2234 Mon Sep 17 00:00:00 2001 2 | From: myfreeer 3 | Date: Tue, 5 Nov 2019 21:19:07 +0800 4 | Subject: [PATCH 3/3] ngx_files: implement ngx_win32_rename_file in utf8 5 | encoding 6 | 7 | --- 8 | src/os/win32/ngx_files.c | 55 +++++++++++++++++++++++++++++++++------- 9 | 1 file changed, 46 insertions(+), 9 deletions(-) 10 | 11 | diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c 12 | index fb413f2..87b3210 100644 13 | --- a/src/os/win32/ngx_files.c 14 | +++ b/src/os/win32/ngx_files.c 15 | @@ -238,18 +238,41 @@ ngx_write_console(ngx_fd_t fd, void *buf, size_t size) 16 | ngx_err_t 17 | ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) 18 | { 19 | - u_char *name; 20 | + u_short *name; 21 | ngx_err_t err; 22 | ngx_uint_t collision; 23 | ngx_atomic_uint_t num; 24 | + size_t to_len; 25 | + u_short to_utf16[NGX_UTF16_BUFLEN]; 26 | + u_short *to_u; 27 | + size_t from_len; 28 | + u_short from_utf16[NGX_UTF16_BUFLEN]; 29 | + u_short *from_u; 30 | + size_t buffer_size; 31 | + 32 | + to_len = NGX_UTF16_BUFLEN; 33 | + to_u = ngx_utf8_to_utf16(to_utf16, to->data, &to_len); 34 | + 35 | + if (to_u == NULL) { 36 | + return NGX_ENOMEM; 37 | + } 38 | 39 | - name = ngx_alloc(to->len + 1 + NGX_ATOMIC_T_LEN + 1 + sizeof("DELETE"), 40 | - log); 41 | + from_len = NGX_UTF16_BUFLEN; 42 | + from_u = ngx_utf8_to_utf16(from_utf16, from->data, &from_len); 43 | + 44 | + if (from_u == NULL) { 45 | + err = NGX_ENOMEM; 46 | + goto failed_to; 47 | + } 48 | + 49 | + buffer_size = to_len + 1 + (NGX_ATOMIC_T_LEN << 1) + 1 + sizeof(L"DELETE"); 50 | + name = ngx_alloc(buffer_size, log); 51 | if (name == NULL) { 52 | - return NGX_ENOMEM; 53 | + err = NGX_ENOMEM; 54 | + goto failed_from; 55 | } 56 | 57 | - ngx_memcpy(name, to->data, to->len); 58 | + ngx_memcpy(name, to_u, to_len); 59 | 60 | collision = 0; 61 | 62 | @@ -258,9 +281,9 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) 63 | for ( ;; ) { 64 | num = ngx_next_temp_number(collision); 65 | 66 | - ngx_sprintf(name + to->len, ".%0muA.DELETE%Z", num); 67 | + swprintf(name + to_len, buffer_size - 1, L".%x.DELETE", num); 68 | 69 | - if (MoveFile((const char *) to->data, (const char *) name) != 0) { 70 | + if (MoveFileW((LPCWSTR) to_u, (LPCWSTR) name) != 0) { 71 | break; 72 | } 73 | 74 | @@ -270,14 +293,14 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) 75 | "MoveFile() \"%s\" to \"%s\" failed", to->data, name); 76 | } 77 | 78 | - if (MoveFile((const char *) from->data, (const char *) to->data) == 0) { 79 | + if (MoveFileW((LPCWSTR) from_u, (LPCWSTR) to_u) == 0) { 80 | err = ngx_errno; 81 | 82 | } else { 83 | err = 0; 84 | } 85 | 86 | - if (DeleteFile((const char *) name) == 0) { 87 | + if (DeleteFileW((LPCWSTR) name) == 0) { 88 | ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, 89 | "DeleteFile() \"%s\" failed", name); 90 | } 91 | @@ -286,6 +309,20 @@ ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) 92 | 93 | ngx_free(name); 94 | 95 | +failed_from: 96 | + if (from_u != from_utf16) { 97 | + err = ngx_errno; 98 | + ngx_free(from_u); 99 | + ngx_set_errno(err); 100 | + } 101 | + 102 | +failed_to: 103 | + if (to_u != to_utf16) { 104 | + err = ngx_errno; 105 | + ngx_free(to_u); 106 | + ngx_set_errno(err); 107 | + } 108 | + 109 | return err; 110 | } 111 | 112 | -- 113 | 2.23.0 114 | 115 | -------------------------------------------------------------------------------- /nginx-0007-logs-write-access-log-to-stderr.patch: -------------------------------------------------------------------------------- 1 | From 1203558f07a960c885af4225109b6525ec06e55e Mon Sep 17 00:00:00 2001 2 | From: myfreeer 3 | Date: Thu, 23 Jan 2020 10:40:30 +0800 4 | Subject: [PATCH] logs: write access log to stderr 5 | 6 | Affecting: 7 | * ngx_http_log_module 8 | * ngx_stream_log_module 9 | --- 10 | src/http/modules/ngx_http_log_module.c | 21 +++++++++++++++++++-- 11 | src/stream/ngx_stream_log_module.c | 12 +++++++++++- 12 | 2 files changed, 30 insertions(+), 3 deletions(-) 13 | 14 | diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c 15 | index f7c4bd2..e6b73ce 100644 16 | --- a/src/http/modules/ngx_http_log_module.c 17 | +++ b/src/http/modules/ngx_http_log_module.c 18 | @@ -1179,6 +1179,7 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) 19 | { 20 | ngx_http_log_loc_conf_t *prev = parent; 21 | ngx_http_log_loc_conf_t *conf = child; 22 | + ngx_str_t name; 23 | 24 | ngx_http_log_t *log; 25 | ngx_http_log_fmt_t *fmt; 26 | @@ -1220,7 +1221,13 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) 27 | 28 | log->file = ngx_conf_open_file(cf->cycle, &ngx_http_access_log); 29 | if (log->file == NULL) { 30 | - return NGX_CONF_ERROR; 31 | + // fall back to stderr 32 | + ngx_str_null(&name); 33 | + cf->cycle->log_use_stderr = 1; 34 | + log->file = ngx_conf_open_file(cf->cycle, &name); 35 | + if (log->file == NULL) { 36 | + return NGX_CONF_ERROR; 37 | + } 38 | } 39 | 40 | lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module); 41 | @@ -1282,7 +1289,17 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 42 | ngx_memzero(log, sizeof(ngx_http_log_t)); 43 | 44 | 45 | - if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) { 46 | + if (ngx_strcmp(value[1].data, "stderr") == 0) { 47 | + ngx_str_null(&name); 48 | + cf->cycle->log_use_stderr = 1; 49 | + 50 | + log->file = ngx_conf_open_file(cf->cycle, &name); 51 | + if (log->file == NULL) { 52 | + return NGX_CONF_ERROR; 53 | + } 54 | + 55 | + goto process_formats; 56 | + } else if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) { 57 | 58 | peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t)); 59 | if (peer == NULL) { 60 | diff --git a/src/stream/ngx_stream_log_module.c b/src/stream/ngx_stream_log_module.c 61 | index 0ff7f42..14ddc74 100644 62 | --- a/src/stream/ngx_stream_log_module.c 63 | +++ b/src/stream/ngx_stream_log_module.c 64 | @@ -1014,7 +1014,17 @@ ngx_stream_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 65 | ngx_memzero(log, sizeof(ngx_stream_log_t)); 66 | 67 | 68 | - if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) { 69 | + if (ngx_strcmp(value[1].data, "stderr") == 0) { 70 | + ngx_str_null(&name); 71 | + cf->cycle->log_use_stderr = 1; 72 | + 73 | + log->file = ngx_conf_open_file(cf->cycle, &name); 74 | + if (log->file == NULL) { 75 | + return NGX_CONF_ERROR; 76 | + } 77 | + 78 | + goto process_formats; 79 | + } else if (ngx_strncmp(value[1].data, "syslog:", 7) == 0) { 80 | 81 | peer = ngx_pcalloc(cf->pool, sizeof(ngx_syslog_peer_t)); 82 | if (peer == NULL) { 83 | -- 84 | 2.25.0 85 | 86 | -------------------------------------------------------------------------------- /nginx-build-msys2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # cmd line switches 4 | for i in "$@" 5 | do 6 | case $i in 7 | -t=*|--tag=*) 8 | NGINX_TAG="${i#*=}" 9 | shift # past argument=value 10 | ;; 11 | esac 12 | done 13 | 14 | # create dir for docs 15 | mkdir -p docs 16 | 17 | # init 18 | machine_str="$(gcc -dumpmachine | cut -d'-' -f1)" 19 | 20 | # workaround git user name and email not set 21 | GIT_USER_NAME="$(git config --global user.name)" 22 | GIT_USER_EMAIL="$(git config --global user.email)" 23 | if [[ "${GIT_USER_NAME}" = "" ]]; then 24 | git config --global user.name "Build Bot" 25 | fi 26 | if [[ "${GIT_USER_EMAIL}" = "" ]]; then 27 | git config --global user.email "nobody@example.com" 28 | fi 29 | 30 | # dep versions 31 | ZLIB="$(curl -s 'https://zlib.net/' | grep -ioP 'zlib-(\d+\.)+\d+' | sort -ruV | head -1)" 32 | ZLIB="${ZLIB:-zlib-1.2.13}" 33 | echo "${ZLIB}" 34 | PCRE="$(curl -s 'https://sourceforge.net/projects/pcre/rss?path=/pcre/' | grep -ioP 'pcre-(\d+\.)+\d+' |sort -ruV | head -1)" 35 | PCRE="${PCRE:-pcre-8.45}" 36 | echo "${PCRE}" 37 | PCRE2="$(curl -s 'https://api.github.com/repos/PhilipHazel/pcre2/releases/latest' | grep -ioP 'pcre2-(\d+\.)+\d+' |sort -ruV | head -1)" 38 | PCRE2="${PCRE2:-pcre2-10.42}" 39 | echo "${PCRE2}" 40 | OPENSSL="$(curl -s 'https://openssl-library.org/source/' | grep -ioP 'openssl-3\.0\.\d+' | sort -ruV | head -1)" 41 | OPENSSL="${OPENSSL:-openssl-3.0.14}" 42 | echo "${OPENSSL}" 43 | 44 | # clone and patch nginx 45 | if [[ -d nginx ]]; then 46 | cd nginx || exit 1 47 | git checkout master 48 | git branch patch -D 49 | if [[ "${NGINX_TAG}" == "" ]]; then 50 | git reset --hard origin || git reset --hard 51 | git pull 52 | else 53 | git reset --hard "${NGINX_TAG}" || git reset --hard 54 | fi 55 | else 56 | if [[ "${NGINX_TAG}" == "" ]]; then 57 | git clone https://github.com/nginx/nginx.git --depth=1 58 | cd nginx || exit 1 59 | else 60 | git clone https://github.com/nginx/nginx.git --depth=1 --branch "${NGINX_TAG}" 61 | cd nginx || exit 1 62 | # You are in 'detached HEAD' state. 63 | git checkout -b master 64 | fi 65 | fi 66 | 67 | git checkout -b patch 68 | 69 | # Since 1.23.4 utf16 encoded pathes are supported natively upstream 70 | # detect function ngx_utf16_to_utf8 introduced since nginx 1.23.4 71 | if [ "$(grep 'ngx_utf16_to_utf8' src/os/win32/ngx_files.c | wc -l)" -ge 2 ]; then 72 | rm -f ../nginx-0002-win32-force-utf-8-encoding-in-ngx_dir_t.patch 73 | rm -f ../nginx-0003-ngx_files-implement-some-functions-in-utf8-encoding.patch 74 | rm -f ../nginx-0004-ngx_files-implement-ngx_open_tempfile-in-utf8-encodi.patch 75 | rm -f ../nginx-0005-ngx_files-implement-ngx_open_glob-and-ngx_read_glob-.patch 76 | rm -f ../nginx-0006-ngx_files-implement-ngx_win32_rename_file-in-utf8-en.patch 77 | fi 78 | 79 | # apply remaining patches 80 | git am -3 ../nginx-*.patch 81 | 82 | set -e 83 | 84 | # download deps 85 | wget -c -nv "https://zlib.net/${ZLIB}.tar.xz" || \ 86 | wget -c -nv "http://prdownloads.sourceforge.net/libpng/${ZLIB}.tar.xz" 87 | tar -xf "${ZLIB}.tar.xz" 88 | WITH_PCRE="${PCRE}" 89 | if grep -q PCRE2_STATIC ./auto/lib/pcre/conf ; then 90 | echo using pcre2 91 | WITH_PCRE="${PCRE2}" 92 | wget -c -nv "https://github.com/PhilipHazel/pcre2/releases/download/${PCRE2}/${PCRE2}.tar.bz2" 93 | tar -xf "${PCRE2}.tar.bz2" 94 | else 95 | wget -c -nv "https://download.sourceforge.net/project/pcre/pcre/$(echo $PCRE | sed 's/pcre-//')/${PCRE}.tar.bz2" 96 | tar -xf "${PCRE}.tar.bz2" 97 | fi 98 | echo using pcre "${WITH_PCRE}" 99 | wget -c -nv "https://www.openssl.org/source/${OPENSSL}.tar.gz" 100 | tar -xf "${OPENSSL}.tar.gz" 101 | 102 | # dirty workaround for openssl-1.1.1d 103 | if [ "${OPENSSL}" = "openssl-1.1.1d" ]; then 104 | sed -i 's/return return 0;/return 0;/' openssl-1.1.1d/crypto/threads_none.c 105 | fi 106 | 107 | # make changes 108 | make -f docs/GNUmakefile changes 109 | mv -f tmp/*/CHANGES* ../docs/ 110 | 111 | # copy docs and licenses 112 | cp -f docs/text/LICENSE ../docs/ || cp -f LICENSE ../docs/ 113 | cp -f docs/text/README ../docs/ || cp -f README.md ../docs/ || cp -f README ../docs/ 114 | if [[ -d docs/html ]]; then 115 | mkdir -p ../html 116 | cp -f docs/html/* ../html/ 117 | fi 118 | cp -pf "${OPENSSL}/LICENSE.txt" '../docs/OpenSSL.LICENSE' 119 | cp -pf "${WITH_PCRE}/LICENCE" '../docs/PCRE.LICENCE' 120 | sed -ne '/^ (C) 1995-20/,/^ jloup@gzip\.org/p' "${ZLIB}/README" > '../docs/zlib.LICENSE' 121 | touch -r "${ZLIB}/README" '../docs/zlib.LICENSE' 122 | 123 | # configure 124 | configure_args=( 125 | --sbin-path=nginx.exe \ 126 | --http-client-body-temp-path=temp/client_body \ 127 | --http-proxy-temp-path=temp/proxy \ 128 | --http-fastcgi-temp-path=temp/fastcgi \ 129 | --http-scgi-temp-path=temp/scgi \ 130 | --http-uwsgi-temp-path=temp/uwsgi \ 131 | --with-http_realip_module \ 132 | --with-http_addition_module \ 133 | --with-http_sub_module \ 134 | --with-http_dav_module \ 135 | --with-http_stub_status_module \ 136 | --with-http_flv_module \ 137 | --with-http_mp4_module \ 138 | --with-http_gunzip_module \ 139 | --with-http_gzip_static_module \ 140 | --with-http_auth_request_module \ 141 | --with-http_random_index_module \ 142 | --with-http_secure_link_module \ 143 | --with-http_slice_module \ 144 | --with-mail \ 145 | --with-stream \ 146 | --with-stream_realip_module \ 147 | "--with-pcre=${WITH_PCRE}" \ 148 | --with-pcre-jit \ 149 | "--with-zlib=${ZLIB}" \ 150 | --with-ld-opt="-Wl,--gc-sections,--build-id=none" \ 151 | --prefix= 152 | ) 153 | 154 | # no-ssl build 155 | echo "${configure_args[@]}" 156 | auto/configure "${configure_args[@]}" \ 157 | --with-cc-opt='-DFD_SETSIZE=1024 -s -O2 -fno-strict-aliasing -pipe' 158 | 159 | # build 160 | make "-j$(nproc)" 161 | strip -s objs/nginx.exe 162 | version="$(cat src/core/nginx.h | grep NGINX_VERSION | grep -ioP '((\d+\.)+\d+)')" 163 | mv -f "objs/nginx.exe" "../nginx-slim-${version}-${machine_str}.exe" 164 | 165 | # re-configure with ssl 166 | configure_args+=( 167 | --with-http_v2_module \ 168 | "--with-openssl=${OPENSSL}" \ 169 | --with-http_ssl_module \ 170 | --with-mail_ssl_module \ 171 | --with-stream_ssl_module \ 172 | --with-stream_ssl_preread_module 173 | ) 174 | echo "${configure_args[@]}" 175 | auto/configure "${configure_args[@]}" \ 176 | --with-cc-opt='-DFD_SETSIZE=1024 -s -O2 -fno-strict-aliasing -pipe' \ 177 | --with-openssl-opt='no-tests -D_WIN32_WINNT=0x0501' 178 | 179 | # build 180 | make "-j$(nproc)" 181 | strip -s objs/nginx.exe 182 | version="$(cat src/core/nginx.h | grep NGINX_VERSION | grep -ioP '((\d+\.)+\d+)')" 183 | mv -f "objs/nginx.exe" "../nginx-${version}-${machine_str}.exe" 184 | 185 | # re-configure with debugging log 186 | configure_args+=(--with-debug) 187 | auto/configure "${configure_args[@]}" \ 188 | --with-cc-opt='-DFD_SETSIZE=1024 -O2 -fno-strict-aliasing -pipe' \ 189 | --with-openssl-opt='no-tests -D_WIN32_WINNT=0x0501' 190 | 191 | # re-build with debugging log 192 | make "-j$(nproc)" 193 | mv -f "objs/nginx.exe" "../nginx-${version}-${machine_str}-debug.exe" 194 | 195 | # clean up 196 | git checkout master 197 | git branch patch -D 198 | cd .. 199 | -------------------------------------------------------------------------------- /nginx-package-msys2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp -rf nginx/conf . 3 | cp -rf nginx/docs/html . 4 | cp -rf nginx/contrib . 5 | rm -rf temp logs 6 | mkdir -p temp 7 | mkdir -p logs 8 | 7z a -mx9 nginx-bin.7z nginx-*.exe contrib docs conf html temp logs --------------------------------------------------------------------------------