OPERATING SYSTEMSOS Linux

How to set up HTTP authentication on Ubuntu using Nginx

Hi everybody, I am Cuong, welcome back to my Magento 2 tutorial video series.
#magento #magento2 #magento2tutorial #http #httpauthentication

In the previous lesson, I showed everybody on How to install magento 2.4 on Ubuntu, if you don’t watch this tutorial yet, you can watch it here https://bit.ly/3piC1f6.

Let’s continue my video series, I am going to share with everybody another practice today.

When you work for a Magento project, the live website and development website will separate. The Magento developers will work on the development website, test the features if everything is fine then will update the new codes to the live site.

Follow this, my website will be separated into two domains giaphugroup.com and staging.giaphugroup.com
1. giaphugroup.com will be the live website
2. staging.giaphugroup.com will be the development website

The Magento developers will work on staging.giaphugroup.com, this domain is private, you don’t want others to be able to access it. Only the members of the team and the client can access it. So how you can resolve this.

To resolve this task. Today, I am going to show everybody on How to set up HTTP authentication on Ubuntu using Nginx.

Okie, let’s go.

Let’s do this practice, you need to follow steps by step:

Step 1: Create the new subdomain called staging.giaphugroup.com
– Create the new folder named staging.giaphugroup.com in the path /var/www/html/
mkdir /var/www/html/staging.giaphugroup.com
– Copy the codes from giaphugroup.com to staging.giaphugroup.com
cp -r /var/www/html/giaphugroup.com/ /var/www/html/staging.giaphugroup.com/
chown -R www-data:www-data /var/www/html/staging.giaphugroup.com/
– Create a new virtual host for accessing staging.giaphugroup.com
cd /etc/nginx/sites-available/
cp giaphugroup.com staging.giaphugroup.com
nano staging.giaphugroup.com then update the server name and root path.
ln -s /etc/nginx/sites-available/staging.giaphugroup.com /etc/nginx/sites-enabled/
nginx -t
service nginx restart
– Create a new database for access on staging.giaphugroup.com
staging will use another database with the live website.
mysql -u root -p
create database giaphugroup_staging;
– Export the database from giaphugroup.com, then import it to the database of staging.giaphugroup.com
mysqldump -u root -p giaphugroup giaphugroup.sql
mysql -u root -p giaphugroup_staging giaphugroup.sql
– Change the database for using on staging.giaphugroup.com
– Update the Magento base URL and clear magento 2 cache
php bin/magento cache:clean
– Go to the domain manager and create the new subdomain called staging.giaphugroup.com then point it to your server.
Okay! it is updated.
– If your server is using Varnish cache for your Magento website. You need to stop the Varnish cache and update the file /etc/nginx/sites-available/staging.giaphugroup.com, change to listen to port 80.
service varnish stop
nano /etc/nginx/sites-available/staging.giaphugroup.com
nginx -t
service nginx restart
– Update SSL certificate for staging.giaphugroup.com, so this domain will be used with https://staging.giaphugroup.com. If your server don’t set up the Letsencrypt yet, please watch this tutorial https://bit.ly/3bCOXHM
certbot –nginx -d staging.giaphugroup.com
Update the file /etc/nginx/sites-available/staging.giaphugroup.com, change to listen to port 8088 again.
nginx -t
service nginx restart
service varnish start

Step 2: Set up HTTP authentication on Ubuntu
1. Installing Apache Utils
apt-get install apache2-utils

2. Create User and Password for accessing
htpasswd -c /etc/nginx/.htpasswd username
replace username by the user name you want to use.
Adding password for user username

3. Update Nginx configuration
Add the two entries below under for the domain path that you want to secure.
nano /var/www/html/staging.giaphugroup.com/nginx.conf
auth_basic “Restricted”;
auth_basic_user_file /etc/nginx/.htpasswd;
nginx -t
service nginx restart

Step 3: Test and see the result
– Access the link staging.giaphugroup.com

Yeah! it works perfectly.

Thank you for your watching. If you have any questions about this practice, please feel free to leave a comment below.

Don’t forget to like, comment, share my videos and subscribe to my channel for getting the latest videos.

Please do not hesitate to contact me, if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2.

source

ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *