Nginx is another most popular web server than Apache HTTP Server. It is used by a large number of popular websites worldwide. This web server is highly useful for heavy traffic websites. This tutorial will help you to install Nginx on Ubuntu 18.04 and 16.04 using apt-get.
In order to install Nginx on Ubuntu, you must have root or sudo privileged user access to your system. For the remote systems can use ssh command or putty for Windows user to login.
2. Install Nginx on Ubuntu
The Nginx latest packages are available under default repositories for all Ubuntu’s versions, You can directly install them by running following commands
sudo apt-get update sudo apt-get install nginx
After installation of Nginx service, run below command to check the status of Nginx service.
sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2018-04-27 15:38:31 IST; 13min ago Docs: man:nginx(8) Process: 3406 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 3405 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 3407 (nginx) Tasks: 2 (limit: 2323) CGroup: /system.slice/nginx.service ├─3407 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─3408 nginx: worker process
3. Configure Firewall
You need to open the firewall port to access Nginx server from remote systems. The following command will allow port 80 (HTTP) and port 443 (HTTPS) on your system.
sudo ufw allow 'Nginx FULL'
You don’t need to open both ports. Use one of the following commands to open specific ports.
sudo ufw allow 'Nginx HTTP' sudo ufw allow 'Nginx HTTPS'
4. Manage Nginx Service
The systemd users use systemctl commands to manage their Nginx service on Ubuntu system. The below commands will stop, star, and restart nginx service.
sudo systemctl stop nginx sudo systemctl start nginx sudo systemctl restart nginx