两种问题,我自己碰到的情况
./nginx -s reload
执行命令后报错
nginx: [error] invalid PID number ““ in “/run/nginx.pid“
第一种情况,pid被注释了
/usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;// 可能是这里被注释了
pid logs/nginx.pid;events {worker_connections 1024;
}http {server {listen 80;server_name localhost;location / {root html;index index.html index.htm;}// ...省略}# HTTPS serverserver {listen 443 ssl;server_name localhost;ssl_certificate 证书文件夹/证书文件夹下的.pem;ssl_certificate_key 证书文件夹/证书文件夹下的.key;ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location / {root html;index index.html index.htm;}}
}
第二种情况 杀死 80 进程,重新启动nginx
root@VM-20-12-ubuntu:/usr/local/nginx/sbin# ./nginxnginx: [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()
启动 nginx
报错,说是 80
端口已经在启动中了,重启也会报标题的错误
直接查看全部进程,netstat -ntlp
root@VM-20-12-ubuntu:/usr/local/nginx/sbin# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6016 0.0.0.0:* LISTEN 64667/sshd: root@pt
tcp 0 0 127.0.0.1:6017 0.0.0.0:* LISTEN 74895/sshd: root@pt
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 81236/sshd: root@pt
tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 8904/sshd: root@pts
tcp 0 0 127.0.0.1:6014 0.0.0.0:* LISTEN 37466/sshd: root@pt
tcp 0 0 127.0.0.1:6015 0.0.0.0:* LISTEN 30768/sshd: root@pt
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 759/systemd-resolve
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17945/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 881/sshd: /usr/sbin
tcp6 0 0 ::1:6016 :::* LISTEN 64667/sshd: root@pt
tcp6 0 0 ::1:6017 :::* LISTEN 74895/sshd: root@pt
tcp6 0 0 ::1:6010 :::* LISTEN 81236/sshd: root@pt
tcp6 0 0 ::1:6012 :::* LISTEN 8904/sshd: root@pts
tcp6 0 0 ::1:6014 :::* LISTEN 37466/sshd: root@pt
tcp6 0 0 ::1:6015 :::* LISTEN 30768/sshd: root@pt
tcp6 0 0 :::23333 :::* LISTEN 785/node
tcp6 0 0 :::3306 :::* LISTEN 1671/mysqld
tcp6 0 0 :::24444 :::* LISTEN 784/node
tcp6 0 0 :::33060 :::* LISTEN 1671/mysqld
tcp6 0 0 :::22 :::* LISTEN 881/sshd: /usr/sbin
可以看到 80
端口正在运行
root@VM-20-12-ubuntu:/usr/local/nginx/sbin# kill 17945
root@VM-20-12-ubuntu:/usr/local/nginx/sbin# ./nginx
杀掉 80
进程后重新启动 nginx
,就成功了
我是在配置 HTTPS
,我这边输入 https://***.**
我的网站也成功显示 https
,链接内容了