![尽管只有 NGINX 在运行,但 bind() 到 0.0.0.0:80 失败(98:地址已在使用中)](https://linux22.com/image/772067/%E5%B0%BD%E7%AE%A1%E5%8F%AA%E6%9C%89%20NGINX%20%E5%9C%A8%E8%BF%90%E8%A1%8C%EF%BC%8C%E4%BD%86%20bind()%20%E5%88%B0%200.0.0.0%3A80%20%E5%A4%B1%E8%B4%A5%EF%BC%8898%EF%BC%9A%E5%9C%B0%E5%9D%80%E5%B7%B2%E5%9C%A8%E4%BD%BF%E7%94%A8%E4%B8%AD%EF%BC%89.png)
注:结果发现根本没有任何问题。详情请参阅评论。
我刚刚从 Oracle Cloud 获得了全新实例,Ubuntu 20.04 Minimized。由于我尝试在此实例上运行 DokuWiki,因此我安装了以下软件包:
sudo apt install net-tools lsof wget nano
sudo apt install php7.4-fpm php7.4-xml php7.4-mbstring imagemagick nginx certbot python3-certbot-nginx
我从未触碰过,nginx.conf
但/etc/nginx
删除了default
符号链接/etc/sites-enabled
,并将我自己的 conf 文件放入/etc/nginx/conf.d
同名文件中example.com.conf
(虽然真实姓名已被删除)
server {
listen 80 default_server;
server_name example.com;
root /var/www/dokuwiki;
index index.php index.html;
location / {
try_files $uri $uri/ @dokuwiki;
}
location @dokuwiki {
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
rewrite ^/(.*) /doku.php?id=$1&$args last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /(conf|bin|inc|vendor)/ {
deny all;
}
location ~ /data/ {
internal;
}
}
当然,由(用户和组)使用以下命令/var/www/dokuwiki
拥有:www-data
sudo chown -R www-data:www-data /var/www/dokuwiki
问题是,我无法访问我的网站。当我nginx
在终端中输入时,它会尖叫如下:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
但是,我检查过没有apache2
类似的东西,也没有其他进程监听端口 80。
root@redacted:~# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1296 root 6u IPv4 32966 0t0 TCP *:http (LISTEN)
nginx 1297 www-data 6u IPv4 32966 0t0 TCP *:http (LISTEN)
nginx 1298 www-data 6u IPv4 32966 0t0 TCP *:http (LISTEN)
root@redacted:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-11-06 13:24:23 UTC; 16min ago
Docs: man:nginx(8)
Process: 1294 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1295 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1296 (nginx)
Tasks: 3 (limit: 1110)
Memory: 3.1M
CGroup: /system.slice/nginx.service
├─1296 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─1297 nginx: worker process
└─1298 nginx: worker process
Nov 06 13:24:23 redacted systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 06 13:24:23 redacted systemd[1]: Started A high performance web server and a reverse proxy server.
root@redacted:~# fuser -v 80/tcp
USER PID ACCESS COMMAND
80/tcp: root 1296 F.... nginx
www-data 1297 F.... nginx
www-data 1298 F.... nginx
由于我没有碰过nginx.conf
,nginx -t
所以说没有错误。但是检查.conf
文件失败:
root@redacted:~# nginx -tc /etc/nginx/conf.d/example.com.conf
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/example.com.conf:1
nginx: configuration file /etc/nginx/conf.d/example.com.conf test failed
但我认为这与这个问题无关(但不确定)。
即使杀死所有使用端口 80 的进程也不起作用。
我已经在 Google 上搜索过此问题的解决方案,但没有找到任何可行的方法。
PS:我已经从 OC 网络面板打开了端口iptables
。所以我认为端口问题不是导致此问题的原因。
答案1
我不知道我是否可以发布我自己的问题的答案,但这是答案。
事实上,我误解了nginx
命令的作用。我以为这会向我显示当前 NGINX 进程的日志,但实际上它试图创建新的 NGINX 进程,而该进程将被当前 NGINX 进程阻止。这就是它向[emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
我显示错误的原因。
所以,总而言之,我的环境没有问题。一切都很好。