I'm new to Nginx and had some trouble here.
I'm using Mac OS and nginx version: nginx/1.17.7.
The first time I downloaded Nginx was some time ago. At that time, everything ran perfectly. Then When I played around with nginx.conf, I messed it up somehow. So, when I restarted learning Nginx today, I removed all the files I had before and reinstalled it through homebrew. Then the issue I wished someone could help me with popped out.
After initializing Nginx, I got this error
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] still could not bind()
I searched for this issue online. There were a lot of answers, but either the solutions were for Linux not Mac, or they just couldn't work.
One of the most promising answers I'd found was to kill the processes that were sort of using the port. By the way, even though I had this error, I could access the page localhost:8080, but it was 403 Forbidden page. Then I tried a command on Terminal: ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep '(nginx|PID)' (source)
This was the output:
PID PPID %CPU VSZ WCHAN COMMAND
21827 1 0.0 4291640 - nginx: master process nginx
21828 21827 0.0 4301348 - nginx: worker process
21831 93689 0.0 4267768 - egrep (nginx|PID)
I didn't (still don't) understand what this told, so I tried to kill all of them through kill -9 <PID>, i.e. kill -9 21827, kill -9 21828, and kill -9 21831.
Then I got an error: -bash: kill: (21827) - Operation not permitted. I just thought maybe sudo could solve this, so I tried sudo kill -9 21827. And this time it worked. I killed all the processes but the third one. When I attempted to sudo kill -9 21831, I got No such process. Then I found out it was because the PID of this process was changing all the time for some reason, so if I didn't catch the exact PID of the process at that exact moment I couldn't kill it. Then I left it there like that.
Then I tried to run nginx on Terminal. This was the output:
nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)
This time I didn't find an answer that had the potential to solve this problem... So I tried to restart nginx through the command sudo nginx -s stop && sudo nginx (source) But this didn't work. It reported nginx: [alert] kill(21827, 15) failed (3: No such process). So I tried another answer provided in the same source: brew services list and then brew services start nginx.
But still I got nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied).
Now I don't know how to solve this problem. Also I tried to reinstall nginx by homebrew. But the previous processes would as they did popped out.
Beside, I tried this command as well: ps aux | grep nginx. This gave me three processes before I killed processes. After all these, I got just
apple 22922 0.0 0.0 4267768 832 s003 S+ 3:09AM 0:00.00 grep nginx
Not sure what this could tell.
Could any help what was going wrong here? Alternatively, could you share the correct initial steps to follow to get Nginx running?

所有评论(0)