nginx failed to start high performance web server, address already in use

Total
0
Shares

You run the command systemctl status nginx.service or sudo systemctl start nginx and bam, you got a scary multi lines error stating that nginx failed to start high performance web server and a reverse proxy server. In this article we will focus on resolving this issue completely.

Reasons of this error

The error is generic. It means there could be multiple reasons for nginx failing to start. Your error logs will show you the reason as to why this is happening. Some of them are –

  • nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
  • nginx: [emerg] unexpected end of file, expecting “;” or “}” in /etc/nginx/c>
  • nginx: [emerg] a duplicate default server for [::]:80 in /etc/nginx/sites-enabled/default
  • nginx: [emerg] unknown directive “stream” in /etc/nginx/nginx.conf
  • nginx: [emerg] directive “root” is not terminated by “;” in /etc/nginx/conf.d/writefreely.conf:6
  • Others..

Let’s look at each of these errors and solve them.

Solutions

1. nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)

This error appears when the nginx port i.e. 80 and 443 are occupied by some other process like Apache. The solution is to kill all the process which are running on these ports and let nginx use them.

First get the list of all the processes that are running on port 80 –

sudo lsof -i:80

Next, we will stop all these processes –

sudo fuser -k 80/tcp

If apache2 is running on this port then you may also stop it directly –

sudo service apache2 stop

Now you may start your nginx server –

sudo service nginx restart

2. nginx: [emerg] unexpected end of file, expecting “;” or “}” in /etc/nginx/c>

This error shows that there is some syntax error in config file. Open the indicated file at /etc/nginx/ and check for the syntax errors in the file.

3. nginx: [emerg] a duplicate default server for [::]:80 in /etc/nginx/sites-enabled/default

This error arises when you have multiple nginx websites running. Since they all are using the same 80 port so there is a clash. The solution is to change ports or if you can disable them like default website, then do that.

First remove or unlink the default website –

sudo unlink /etc/nginx/sites-enabled/default

# OR

sudo rm /etc/nginx/sites-enabled/default

Restart the nginx server –

sudo service nginx restart

4. nginx: [emerg] unknown directive “stream” in /etc/nginx/nginx.conf

nginx use the stream module and if we load it dynamically then nginx fails to start and throw this error. To resolve it, you need to statically add the stream module.

First open the nignx.conf file located at /etc/nignx/nginx.conf and add the below code at the very top of this file –

load_module /usr/lib/nginx/modules/ngx_stream_module.so;

Here you need to check whether this ngx_stream_module is located in lib or lib64 on your operating system. In CentOS it is in lib64. So, the address will change to –

load_module /usr/lib64/nginx/modules/ngx_stream_module.so;

Then save the nginx.conf file and run these commands in your terminal –

nginx -t
nginx -s reload
service nginx restart

5. nginx: [emerg] directive “root” is not terminated by “;” in /etc/nginx/conf.d/writefreely.conf:6

This is again a syntax error in a file. It is saying that “root” is not terminated by semicolon. So, solution is to open the file located at /etc/nginx/conf.d/writefreely.conf, move to line number 6 and add a semicolon at the end.

6. Error in configuration file

If there is some error in configuration file then you can understand it by running this command –

nginx -t -c /etc/nginx/nginx.conf

Once you find the bug, you can resolve it and then restart the nginx server –

sudo service nginx restart

Conclusion

In this article we saw various reasons for error “nginx: failed to start high performance web server and a reverse proxy server”. In your case, the reason could be different but solution will be one of our provided ones.