Monday, June 27, 2022

How to install Nginx and apache HTTP server on Ubuntu

Nginx is an open source HTTP web server that is often used as reverse proxy or HTTP cache. Nginx is popular for high-performance, speed, stability and low resource consumption.

In this article, we will walk through installing and setting up NginX server on Ubuntu. Follow these steps to install and setup NginX on your ubuntu.

Requirement

You need to be logged in non-root user with sudo permission. 

Installing Nginx

Nginx is available Ubuntu's default repository, so you can directly install with below command.

sudo apt-get update
sudo apt-get install nginx

After installing it, open your browser and run your server IP address. If you see this page, then you have successfully installed Nginx on your Ubuntu. This default page placed at /var/www/html/ location.

Configure Nginx

Check ufw application list with below command.

sudo ufw app list

Add Nginx to use port 80.

sudo ufw allow 'Nginx HTTP'

If you want to check Nginx server status, then you can run following command.

sudo systemctl status nginx

Add websites to Nginx

When using multiple websites, you need to add your websites to Nginx configuration. For that first create a new Nginx configration file.

sudo nano /etc/nginx/sites-available/website

And put the site details in it.

server {
    listen 80;
    listen [::]:80;

    root /var/www/html/website;
    index index.html index.htm index.nginx-debian.html;

    server_name website www.website.com;

    location / {
            try_files $uri $uri/ =404;
    }
}

Now create a website folder /var/www/html/website. And also give 755 permission.

sudo mkdir /var/www/html/website
sudo chmod -R 7555 /var/www/html/website

Now create simple page for website homepage.

sudo nano /var/www/html/website/index.html

And put any HTML code to check.

<!DOCTYPE html>
<html>
<head>
    <title>Hello World!</title>
</head>
<body>
    <h1>Hello World!</h1>
    <p>Welcome to Website.com</p>
</body>
</html>

Save this file. And now restart the Nginx server.

sudo systemctl restart nginx

Now open your and open your website. you should get your page.



Apache is open-source and most widely used web server in the world. It provides dynamic modules, and powerful support to website.

In this article, we will go through on how to install Apache web server in your Ubuntu 20.04 system.

Prerequisites:

You should have non-root user account logged in with sudo privileges to install Apache server.

Install apache2 server

Apache is already included in Ubuntu's repository, So you can directly install apache server from the Terminal command.

First update the repository index with bellow command.

sudo apt-get update

Install Apache server:

sudo apt-get install apache2

Configure apache server

First check the Apache in ufw application list.

sudo ufw app list

And allow the Apache server

sudo ufw allow 'Apache'

You can also check the ufw status

sudo ufw status

Apache server status

You can check the apache server status with the command:

sudo systemctl status apache2

Start the Apache server

sudo service apache2 start

Or stop the server

sudo service apache2 stop

This way, you can also restart the server

sudo service apache2 restart

This way you can setup your Apache to your server. If you have any suggestions or query, please let us know in the bellow comment section.

Sunday, June 26, 2022

How to install SSL certificate on Ubuntu server

 SSL certificate is becoming mandatory for web application. All modern web browsers are blocking request and ask user permission to proceed.

In this article, I will share you how you can install SSL certificate using Terminal access.

After you logged in to server, First generate CSR using openssl command.

openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr

This will ask few question through wizard. Answer them and proceed for next step.

Now we need to configure Apache server to use .key and .csr certificate files from home directory. Apache main configuration file located at /etc/apache2/sites-available/000-default.conf file. Open the file using nano editor and change file.

<VirtualHost *:443>
    ServerAdmin admin@yourdomain.com
    DocumentRoot /var/www/html
    ServerName Domain name (Ex - test.com)
    ServerAlias www.yourdomain (www.test.com)
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/c09fdeafb99483d9.crt (path from crt file which generate from godaddy (.crt file))
    SSLCertificateKeyFile /etc/apache2/ssl/bsstgulm.key (path from key file when generate the csr for domain)
    SSLCACertificateFile /etc/apache2/ssl/gd_bundle-g2-g1.crt path from crt file which generate from godaddy (.crt file))
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
       ServerName Domain name (Ex - test.com)
    ServerAlias www.yourdomain.com (www.test.com)
    Redirect permanent / https://www.yourdomain.com
</VirtualHost>

In Terminal go to this /etc/apache2/ path and run the below command:

apache2ctl configtest
a2enmod ssl

Lastly you will need to restart Apache server.

sudo service apache2 restart

Now your domain will be ssl certificate installed. I hope this article will help you.


Link: https://hackthestuff.com/article/how-to-install-ssl-certificate-on-ubuntu-server