Junior — Middle
How can you verify that Nginx is listening on the specified port?
sobes.tech AI
Answer from AI
To check if Nginx is listening on a specified port, several methods can be used:
- netstat or ss command
netstat -tuln | grep :80
# or
ss -tuln | grep :80
If a line with the desired port (e.g., 80) appears in the output, Nginx is listening on that port.
- Using curl or telnet
curl -I http://localhost:80
# or
telnet localhost 80
If the connection is established and a response is received, the port is open and listening.
- Checking Nginx configuration
Look at the configuration file (usually /etc/nginx/nginx.conf or in /etc/nginx/sites-enabled/) for the listen directive.
- Nginx logs
If Nginx is running, error logs may contain information about the ports it listens on.
By combining configuration checks and network commands, you can verify that Nginx is listening on the required port.