解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程
作者:mmseoamin日期:2024-02-20

Nginx启动不起来的现象:Nginx启动后,查找不到Nginx进程

分析原因:可以先进入 nginx-1.12.1\logs 路径下,打开error.log文件,可以发现错误日志:

启动Nginx报错:10013:An attempt was made to access a socket in a way forbidden by its access permissions

由错误日志可以发现Nginx启动不起来的原因是:80端口被占用,Nginx绑定失败

解决方法及操作步骤:

1、以管理身份打开cmd,用netstat -ano命令 查一下80端口使用情况

解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,在这里插入图片描述,第1张

2、netstat -ano | findstr “80” 就可以找到被占用进程的PID

解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,](https://img-blog.csdnimg.cn/4fb9d6c866b8449fbb83cedd9dc13b9f.png),第2张

3、强制停止该进程 net stop http

解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,在这里插入图片描述,第3张

4、注意:如若占用80端口的服务/程序不能关闭,出现错误: 无法终止 PID 为 4 的进程,则可能是80端口被系统程序占用,一般为World Wide Web服务或者是sqlserver端口占用。

  • 右键此电脑-管理-服务,找到World Wide Web发布服务,停止并把启动方式设置为手动。

    解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,在这里插入图片描述,第4张

    - 如果装有SQL,请按照下图所示关闭SQL部分服务

    解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,在这里插入图片描述,第5张

  • 然后用netstat -ano命令重新查看是否还有80,如下图,已经没了80端口。此时重启Nginx即可。

    解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,在这里插入图片描述,第6张

    5.如果以上都无法解决,那就更改Nginx监听的端口号吧

    在 nginx-1.12.1\conf 路径下,打开nginx.conf文件,将监听的端口80 修改为 8090,重新启动Nginx

    解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,在这里插入图片描述,第7张

    接下来返回任务管理器,就可以看见两个nginx.exe进程,表示Nginx成功启动了,接下来就可以运行Nginx服务了。

    解决:An attempt was made to access a socket in a way forbidden by its access permissions和无法终止 PID为4的进程,在这里插入图片描述,第8张