douyan1453
douyan1453
2017-12-19 22:31
浏览 47
已采纳

Nginx服务器错误连接到端口

I'm trying to connect my port 7979 to nginx and it doesn't work. I was on localhost:7979/myproject/app/index.php but when I restarted my mac and I updated it, I now see the error message:

ERR_CONNECTION_REFUSED

When I try sudo nginx I see the following messages.

nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] still could not bind()

Port 80 is functioning. If I go to localhost:80 I see this message in the html page:

Default website Congratulations, your Nginx seems to work just fine. :)

Why am I unable to use port 7979?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试将端口7979连接到nginx,但它不起作用。 我在localhost:7979 / myproject / app / index.php但是当我重新启动我的mac并更新它时,我现在看到错误消息:

ERR_CONNECTION_REFUSED

当我尝试sudo nginx时,我看到以下消息。

  nginx:[emerg] bind() 到0.0.0.0:80失败(48:地址已在使用中)
nginx:[emerg] bind()到0.0.0.0:443失败(48:地址已在使用中)
nginx:[emerg] bind()为0.0  .0.0:306失败(48:地址已在使用中)
nginx:[emerg] bind()到0.0.0.0:80失败(48:地址已在使用中)
nginx:[emerg] bind()到0.0.0.0  :443失败(48:地址已在使用中)
nginx:[emerg] bind()到0.0.0.0:30失败(48:地址已在使用中)
nginx:[emerg] bind()到0.0.0.0:80 失败(48:地址已在使用中)
nginx:[emerg] bind()到0.0.0.0:443失败(48:地址已在使用中)
nginx:[emerg] bind()到0.0.0.0:30失败(  48:已经在使用的地址)
nginx:[emerg] bind()到0.0.0.0:80失败(48:地址已经在 使用)
nginx:[emerg] bind()到0.0.0.0:443失败(48:地址已经在使用中)
nginx:[emerg] bind()到0.0.0.0:30失败(48:地址已经在使用中)  
nginx:[emerg] bind()到0.0.0.0:80失败(48:地址已经在使用中)
nginx:[emerg] bind()到0.0.0.0:443失败(48:地址已经在使用中)
nginx  :[emerg] bind()到0.0.0.0:30失败(48:地址已经在使用中)
nginx:[emerg]仍然无法绑定()
   
 
 

端口80正在运行。 如果我转到localhost:80我在html页面中看到此消息:

默认网站恭喜,您的Nginx似乎工作正常。 :)

为什么我无法使用端口7979?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtjbcda841554
    dtjbcda841554 2017-12-20 01:54
    已采纳

    I changed the root and the port and it worked on site-available/default. The root by default wasn't good i don't know why it changed when i restarted my mac. THan

    点赞 评论
  • doutang7415
    doutang7415 2017-12-20 02:05

    It's difficult to troubleshoot with this little info available. So first:

    An error message like nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use) indicates that something is already listening on port 80 and hence nginx can't do that as well when you start it.

    Assuming your configuration files are perfectly ok, you'll have to figure out what is already listening on ports 80, 443 and 306. It might be an instance of nginx that's running with an older configuration but without much more details thats' just a guess.

    See what processes are running:

    $ ps -ax

    See if there's an nginx instance running:

    $ ps -ax | grep nginx

    Netstat can give you what ports are being listened to:

    $ nestat -an | grep LISTEN

    To find out which process is listening to a given port:

    $ sudo lsof -i :631

    (631 is just an example)

    What I suspect: you're starting nginx while it's already running. If it's already running, you should restart it instead of starting a new copy.

    This might be of help: https://serverfault.com/questions/225948/how-to-restart-nginx-on-mac-os-x In essence:

    $ sudo nginx -s reload

    Just a warning I don't run nginx on macOS, but it should work if nginx on macOS reacts like it does on FreeBSD (which macOS uses as a long distant base)

    点赞 评论

相关推荐