Install Config Wiki

All about installing, configuring and troubleshooting

User Tools

Site Tools


install_nqinx_webserver_linux_ubuntu_server_20_04_lts

This is an old revision of the document!


Install Nginx Webserver on Linux Ubuntu Server 20.04 LTS

$ sudo apt update
sudo apt upgrade 

Stop apache2 if that webserver is also installed and running.

sudo systemctl stop apache2.service

Installing Nginx Server

sudo apt install nginx

After the installation is completed, start the Nginx service and enable it to launch every time at system boot. Check the status of Nginx.

sudo systemctl start nginx

sudo systemctl enable nginx

sudo systemctl status nginx

NGinx Could not Bind to http port 80 because Apache is already Bind to that Port

Jun 10 02:33:16 xsvr nginx[77940]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 10 02:33:16 xsvr nginx[77940]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

Jun 10 02:33:17 xsvr nginx[77940]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 10 02:33:17 xsvr nginx[77940]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

Jun 10 02:33:17 xsvr nginx[77940]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Jun 10 02:33:17 xsvr nginx[77940]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

Jun 10 02:33:18 xsvr nginx[77940]: nginx: [emerg] still could not bind() Jun 10 02:33:18 xsvr systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE

Jun 10 02:33:18 xsvr systemd[1]: nginx.service: Failed with result 'exit-code'.

Jun 10 02:33:18 xsvr systemd[1]: Failed to start A high performance web server and a reverse proxy server.

Change Apache2 Default Port to Custom Port on Ubuntu / Debian

Change Apache port on Debian/Ubuntu. Edit /etc/apache2/ports.conf file, $ sudo vi /etc/apache2/ports.conf. Find the following line: Listen 80. ..

sudo vim /etc/apache2/ports.conf

Find the following line:

Listen 80

Change it to a random port of you choice, for example 8090.

Listen 8090 

This entry make the server to accept connections on port 8090 on all interfaces. To make the server accept connections on port 8090 for a specific interface, just include the corresponding network interface’s IP address as shown below.

Listen 192.168.1.101:8090

This will be helpful if your server has multiple IP addresses or network interfaces.

Save and close the file.

If the ports.conf file also has the following, may need to change ssl port 443 to port 444 or something else.

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

Additionally, in Ubuntu and Debian, you also have to change the port number in /etc/apache2/sites-enabled/000-default.conf file too.

$ sudo vi /etc/apache2/sites-enabled/000-default.conf

Find the following line and change the port number.

<VirtualHost *:8090>

Save and close the file.

Then, restart Apache service to take effect the changes.

$ sudo systemctl restart apache2

Now let us verify the port settings:

$ sudo netstat -tulpn | grep :8090

Sample Output:

tcp6     0       0:::880         :::*    LISTEN      4066/apache2 
install_nqinx_webserver_linux_ubuntu_server_20_04_lts.1591759578.txt.gz · Last modified: 2020/06/10 03:26 by wikiadmin