Based on the nginx service status output you've shared, the issue is clear: nginx is failing to start because it cannot bind to ports 80 and 443. The error messages show:
nginx: [emerg] bind() to 0.0.0.0:80 failed
nginx: [emerg] bind() to 0.0.0.0:443 failed
This typically means that ports 80 and 443 are already in use by another process. Here are the steps to diagnose and fix this issue:

1. Check what's using ports 80 and 443
Run these commands to see what processes are currently using these ports:
# Check what's using port 80
sudo netstat -tlnp | grep :80
# Check what's using port 443
sudo netstat -tlnp | grep :443
# Alternative using ss command
sudo ss -tlnp | grep :80
sudo ss -tlnp | grep :443
# Or using lsof
sudo lsof -i :80
sudo lsof -i :443
2. Common causes and solutions
If Apache is running:
# Stop Apache if it's running
sudo systemctl stop apache2
# or
sudo systemctl stop httpd
# Disable Apache from starting automatically
sudo systemctl disable apache2
# or
sudo systemctl disable httpd
If another nginx instance is running:
# Check for running nginx processes
ps aux | grep nginx
# Kill any existing nginx processes
sudo pkill nginx
# or more forcefully
sudo pkill -9 nginx
If Docker containers are using these ports:
# List running containers
docker ps
# Stop containers using these ports
docker stop <container_id>
3. Start nginx after resolving conflicts
Once you've identified and stopped the process using ports 80/443:
# Start nginx
sudo systemctl start nginx
# Check status
sudo systemctl status nginx
# Enable nginx to start on boot
sudo systemctl enable nginx
4. Alternative: Change nginx ports
If you need both services running, you can configure nginx to use different ports by editing the configuration:
# Edit nginx configuration
sudo nano /etc/nginx/sites-available/default
# or
sudo nano /etc/nginx/nginx.conf
Change the listen directives from:
listen 80;
listen 443 ssl;
To something like:
listen 8080;
listen 8443 ssl;
Then restart nginx:
sudo systemctl restart nginx
The most common cause is that Apache or another web server is already running on these ports. Check what's using the ports first, then stop the conflicting service.

2591

被折叠的 条评论
为什么被折叠?



