Day: June 30, 2020

Making the following update to your Nginx .conf file will prevent your website from being accessed directly by it’s IP address

You’ll need to create a new server block and configure it such that any requests to the servers IP address will instead be redirected to the domain name.

server {
    listen 80;
    
    # Listen to your server ip address
    server_name 111.111.111.111; 
    
    # Redirect all traffic comming from your-server-ip to your domain
    return 301 $scheme://example.com$request_uri;
}

Now, when a request is made to 111.111.111.111 it will be redirected to example.com.

I noticed that on my CentOS 6 box, I was still running nginx 1.0.15. I wanted to upgrade to nginx 1.10.1. However, when I ran sudo yum update nginx, it showed that there were no Packages marked for Update.

Luckily, getting the latest version through Yum is straight-forward and only requires adding a new repo. First, create a new file, nginx.repo, in the yum repo directory.

$ vim /etc/yum.repos.d/nginx.repo

Next, give it the following contents:

[nginx] 
name=nginx repo  
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/  
gpgcheck=0  
enabled=1  

Save the file, then shut down the nginx service (unnecessary if nginx wasn’t on the system previously)

$ sudo service nginx stop  

Now, run the yum update command again (or install if nginx wasn’t on the system previously)

$ sudo yum update nginx

It should now let you update to the latest version! As soon as you install the new version, start nginx back up.

$ sudo service nginx start

The way to reset the root password on centos7 is totally different to Centos 6. Let me show you how to reset root password in CentOS 7.

1 – In the boot grub menu select option to edit.

Selection_003

2 – Select Option to edit (e).

Selection_005

3 – Go to the line of Linux 16 and change ro with rw init=/sysroot/bin/sh.

Selection_006

4 – Now press Control+x to start on single user mode.

Selection_007

5 – Now access the system with this command.

chroot /sysroot

6 – Reset the password.

passwd root

7 – Update selinux information

touch /.autorelabel

8 – Exit chroot

exit

9 – Reboot your system

reboot

That’s it. Enjoy.