Opened 2 years ago
Closed 2 years ago
#2394 closed defect (invalid)
[Windows] nginx does not stop after Ctrl+C
Reported by: | 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 )
Attachments (1)
Change History (5)
by , 2 years ago
Attachment: | warning.png added |
---|
comment:1 by , 2 years ago
Description: | modified (diff) |
---|
comment:2 by , 2 years ago
follow-up: 4 comment:3 by , 2 years 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!
comment:4 by , 2 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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.
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, usenginx -s stop
.With
daemon off;
nginx listens for console events and should stop on Ctrl-C just fine, logging something likeCtrl-C pressed, exiting
at the "notice" level. Are you seeing issues withdaemon 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.)