禁止 nginx 使用 80 端口
Disable nginx from using port 80
我的nginx 1.8版本安装在/etc/nginx
下
当我启动 nginx 时,出现以下端口已在使用错误。
sudo systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
$ systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2020-11-27 06:24:18 UTC; 6s ago
Docs: http://nginx.org/en/docs/
Process: 24226 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
Nov 27 06:24:16 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:16 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:17 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:17 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:18 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:18 efendibey_live nginx[24226]: nginx: [emerg] still could not bind()
Nov 27 06:24:18 efendibey_live systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 27 06:24:18 efendibey_live systemd[1]: Failed to start nginx - high performance web server.
Nov 27 06:24:18 efendibey_live systemd[1]: Unit nginx.service entered failed state.
Nov 27 06:24:18 efendibey_live systemd[1]: nginx.service failed.
$
我确定在 nginx.conf 或 /etc/nginx/conf.d/default.conf 中没有指定端口 80。事实上,nginx home目录下的任何文件都没有80端口。
cd /etc/nginx
find . -name "*" | xargs grep 80
输出:
grep: .: Is a directory
grep: ./conf.d: Is a directory
grep: ./default.d: Is a directory
grep: ./certs: Is a directory
grep: ./modules: Is a directory
./conf.d/default.conf: # proxy the PHP scripts to Apache listening on 127.0.0.1:80
./certs/efendibey.de_privatekey.txt:Lm4er4hrt7PhgBir4DWC/bDOIIlhPdXWCr80v2V9hFdTc0CxDA39/ILl054Jjp4L
./certs/ca_bundle.crt:2SAeepyImJ2CzB80YG7WxlynHqNhpE7xfC7PzQlLgmfEHdU+tHFeQazRQnrFkW2W
./nginx.conf: listen [::]:7080 ipv6only=on default_server;
./win-utf: 82 E2809A ; # single low-9 quotation mark
./win-utf: 84 E2809E ; # double low-9 quotation mark
./win-utf: 85 E280A6 ; # ellipsis
./win-utf: 86 E280A0 ; # dagger
./win-utf: 87 E280A1 ; # double dagger
./win-utf: 89 E280B0 ; # per mille
./win-utf: 91 E28098 ; # left single quotation mark
./win-utf: 92 E28099 ; # right single quotation mark
./win-utf: 93 E2809C ; # left double quotation mark
./win-utf: 94 E2809D ; # right double quotation mark
./win-utf: 95 E280A2 ; # bullet
./win-utf: 96 E28093 ; # en dash
./win-utf: 97 E28094 ; # em dash
./win-utf: F0 D180 ; # small r
./koi-utf: 80 E282AC ; # euro
./koi-utf: 95 E280A2 ; # bullet
./koi-utf: D2 D180 ; # small r
./koi-win: 80 88 ; # euro
此外,
$ grep server *.* conf.d/*.*
grep: conf.d: Is a directory
grep: default.d: Is a directory
nginx.conf: server {
nginx.conf: listen [::]:7080 ipv6only=on default_server;
nginx.conf: server_name 199.247.23.57;
nginx.conf: server {
nginx.conf:# server_name efendibey.de; # managed by Certbot
nginx.conf: server_name 199.247.23.57
conf.d/default.conf:server {
conf.d/default.conf: server_name localhost;
conf.d/default.conf: # redirect server error pages to the static page /50x.html
conf.d/default.conf: # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
当我释放80端口后nginx就可以成功启动了
能否请您建议 nginx 为什么以及从哪里选择端口 80?
您需要在 all 您的 server
nginx 配置块中明确指定监听端口(您可以使用 nginx -T
检查所有包含的文件命令),因为作为 listen
指令文档 states:
If the directive is not present then either *:80
is used if nginx runs with the superuser privileges, or *:8000
otherwise.
我的nginx 1.8版本安装在/etc/nginx
下当我启动 nginx 时,出现以下端口已在使用错误。
sudo systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
$ systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2020-11-27 06:24:18 UTC; 6s ago
Docs: http://nginx.org/en/docs/
Process: 24226 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
Nov 27 06:24:16 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:16 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:17 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:17 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:18 efendibey_live nginx[24226]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Nov 27 06:24:18 efendibey_live nginx[24226]: nginx: [emerg] still could not bind()
Nov 27 06:24:18 efendibey_live systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 27 06:24:18 efendibey_live systemd[1]: Failed to start nginx - high performance web server.
Nov 27 06:24:18 efendibey_live systemd[1]: Unit nginx.service entered failed state.
Nov 27 06:24:18 efendibey_live systemd[1]: nginx.service failed.
$
我确定在 nginx.conf 或 /etc/nginx/conf.d/default.conf 中没有指定端口 80。事实上,nginx home目录下的任何文件都没有80端口。
cd /etc/nginx
find . -name "*" | xargs grep 80
输出:
grep: .: Is a directory
grep: ./conf.d: Is a directory
grep: ./default.d: Is a directory
grep: ./certs: Is a directory
grep: ./modules: Is a directory
./conf.d/default.conf: # proxy the PHP scripts to Apache listening on 127.0.0.1:80
./certs/efendibey.de_privatekey.txt:Lm4er4hrt7PhgBir4DWC/bDOIIlhPdXWCr80v2V9hFdTc0CxDA39/ILl054Jjp4L
./certs/ca_bundle.crt:2SAeepyImJ2CzB80YG7WxlynHqNhpE7xfC7PzQlLgmfEHdU+tHFeQazRQnrFkW2W
./nginx.conf: listen [::]:7080 ipv6only=on default_server;
./win-utf: 82 E2809A ; # single low-9 quotation mark
./win-utf: 84 E2809E ; # double low-9 quotation mark
./win-utf: 85 E280A6 ; # ellipsis
./win-utf: 86 E280A0 ; # dagger
./win-utf: 87 E280A1 ; # double dagger
./win-utf: 89 E280B0 ; # per mille
./win-utf: 91 E28098 ; # left single quotation mark
./win-utf: 92 E28099 ; # right single quotation mark
./win-utf: 93 E2809C ; # left double quotation mark
./win-utf: 94 E2809D ; # right double quotation mark
./win-utf: 95 E280A2 ; # bullet
./win-utf: 96 E28093 ; # en dash
./win-utf: 97 E28094 ; # em dash
./win-utf: F0 D180 ; # small r
./koi-utf: 80 E282AC ; # euro
./koi-utf: 95 E280A2 ; # bullet
./koi-utf: D2 D180 ; # small r
./koi-win: 80 88 ; # euro
此外,
$ grep server *.* conf.d/*.*
grep: conf.d: Is a directory
grep: default.d: Is a directory
nginx.conf: server {
nginx.conf: listen [::]:7080 ipv6only=on default_server;
nginx.conf: server_name 199.247.23.57;
nginx.conf: server {
nginx.conf:# server_name efendibey.de; # managed by Certbot
nginx.conf: server_name 199.247.23.57
conf.d/default.conf:server {
conf.d/default.conf: server_name localhost;
conf.d/default.conf: # redirect server error pages to the static page /50x.html
conf.d/default.conf: # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
当我释放80端口后nginx就可以成功启动了
能否请您建议 nginx 为什么以及从哪里选择端口 80?
您需要在 all 您的 server
nginx 配置块中明确指定监听端口(您可以使用 nginx -T
检查所有包含的文件命令),因为作为 listen
指令文档 states:
If the directive is not present then either
*:80
is used if nginx runs with the superuser privileges, or*:8000
otherwise.