#2394 closed defect (invalid)

[Windows] nginx does not stop after Ctrl+C

Reported by: horvoje@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.21.x
Keywords: stop, exit, process, CtrlC Cc: horvoje@…
uname -a: MINGW64_NT-10.0-22621 DESKTOP-NPOA8V1 3.3.5-341.x86_64 2022-07-08 09:41 UTC x86_64 Msys
nginx -V: nginx version: nginx/1.23.1
built by cl 16.00.30319.01 for 80x86
built with OpenSSL 1.1.1q 5 Jul 2022
TLS SNI support enabled
configure arguments: --with-cc=cl --builddir=objs.msvc8 --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs.msvc8/lib/pcre2-10.39 --with-zlib=objs.msvc8/lib/zlib-1.2.12 --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-openssl=objs.msvc8/lib/openssl-1.1.1q --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module

nginx version: nginx/1.21.6
built by cl 16.00.40219.01 for 80x86
built with OpenSSL 1.1.1m 14 Dec 2021
TLS SNI support enabled
configure arguments: --with-cc=cl --builddir=objs.msvc8 --with-debug --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --http-scgi-temp-path=temp/scgi_temp --http-uwsgi-temp-path=temp/uwsgi_temp --with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=objs.msvc8/lib/pcre2-10.39 --with-zlib=objs.msvc8/lib/zlib-1.2.11 --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-openssl=objs.msvc8/lib/openssl-1.1.1m --with-openssl-opt='no-asm no-tests -D_WIN32_WINNT=0x0501' --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module

Description (last modified by horvoje@…)

After latest Windows 11 update (22H2), nginx won't stop after pressing Ctrl+C.
If I close command prompt window, nginx continues to run as a background process.
Tried with Windows Command Prompt and also with Git Bash Shell.
Tried with nginx versions 1.21.6 and 1.23.1


Attachments (1)

warning.png (6.9 KB ) - added by horvoje@… 19 months ago.

Download all attachments as: .zip

Change History (5)

by horvoje@…, 19 months ago

Attachment: warning.png added

comment:1 by horvoje@…, 19 months ago

Description: modified (diff)

comment:2 by Maxim Dounin, 19 months ago

Could you please clarify nginx configuration you are using?

With daemon on; (the default), nginx starts as a daemon, so it detaches from the console and cannot be stopped by pressing Ctrl-C and/or closing the terminal window. To avoid confusion, it might be a good idea to start it with start nginx, so there will be no window from the start, see here. To stop running nginx instance, use nginx -s stop.

With daemon off; nginx listens for console events and should stop on Ctrl-C just fine, logging something like Ctrl-C pressed, exiting at the "notice" level. Are you seeing issues with daemon off; on Windows 11?

(Note well that MinGW/MSYS shell might incorrectly kill nginx master process on Ctrl-C, see here. It is generally a good idea to test from the native terminal instead.)

comment:3 by horvoje@…, 19 months ago

I'm using nginx in Windows so I'm not sure what would be 'natural terminal' in Windows.
So far I found two options to start it as a process, not a service: a) from Windows Command Prompt and b) from Git Bash shell.
Both options are working the same way with only difference that Git Bash shell pops up a alert (please see attachment in original post) about processes running when I click close icon on shell window.

Regarding nginx installation and configuration, I did it many months ago and it was working fine without even knowing about daemon option.
My wish is to use it as a process from command prompt / shell to be able to start it only when needed. If I install it as a Windows serivce, then things get complicated for me. I cannot say it can't be done but for sure starting it as a process from command line is far better in my case.

Regarding 'daemon on' and 'daemon off' - I never did that kind of configurataion and if "on" is a default value, then there was a mystery on my computer because Ctrl+C was stopping it until last Windows update.

Here is the script I used to use to start it and it's the same many months, no changes applied ever. The script is called from Git Bash shell:

File: run-nginx-windows.sh

echo Starting nginx...
echo e:/app/nginx
echo Press Ctrl+C for abort
cd /e/app/nginx
./nginx.exe

Today I changed my script and added 'daemon off' directive and now it's possible to stop it with Ctrl+C;

./nginx -g 'daemon off;'

To be honest, I don't know what happened but I know nothing changed in my dev environment except already mentioned Windows update.
Prior to this update I was able to stop it without having 'daemon off' in start script.

Thanks a lot for your info!

P.S. At the production level I'm using Ubuntu LTS and, of course, nginx is installed as a service.

Last edited 19 months ago by horvoje@… (previous) (diff)

in reply to:  3 comment:4 by Maxim Dounin, 19 months ago

Resolution: invalid
Status: newclosed

Replying to horvoje@…:

I'm using nginx in Windows so I'm not sure what would be 'natural terminal' in Windows.
So far I found two options to start it as a process, not a service: a) from Windows Command Prompt and b) from Git Bash shell.
Both options are working the same way with only difference that Git Bash shell pops up a alert (please see attachment in original post) about processes running when I click close icon on shell window.

By native terminal on Windows I of course mean "Command Prompt", cmd.exe.

With daemon on;, it is not expected to be possible to stop nginx with Ctrl-C. If this previously worked for you, most likely it's because your shell handled it for you somehow. It is certainly not possible with native command prompt, cmd.exe, at least with Windows 10 21H1.

Either way, thanks for the details. As previously suggested, if you want to be able to stop nginx with Ctrl-C, using daemon off; is the proper way to go. Alternatively, you can use nginx -s stop to stop nginx if it's started as a daemon.

Note: See TracTickets for help on using tickets.