Selasa, 16 Juli 2019

How to Install Nginx on CentOS 7


How to Install Nginx on CentOS 7

Nginx [engine x] is free and open source high-performance web server. It also acts as a reverse proxy server, as well as. This page shows how to install Nginx server on a CentOS 7 or RHEL 7 and configure a static web site.

In this article, we will explain how to install, configure and manage Nginx HTTP web server on a CentOS 7 or RHEL 7 server using command line.


Install Nginx Web Server
  1. First update the system software packages to the latest version.

  2. # yum -y update

  3. Next, install Nginx HTTP server from the EPEL repository using the YUM package manager, or if you have not installed the epel repository you can install the nginx repository.

  4. Configure EPEL repo

    # yum install epel-release

    Configure Nginx repo for CentOS 7 & RHEL (Red Hat Enterprise Linux) version 7.x

    # vi /etc/yum.repos.d/nginx.repo

    Append following for CentOS 7.x:

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

    Append following for RHEL (Red Hat Enterprise Linux) version 7.x:

    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/mainline/rhel/7/$basearch/
    gpgcheck=0
    enabled=1

    Next, install Nginx

    # yum install nginx


Manage Nginx HTTP Server
  1. Once Nginx web server installed, you can start it first time and enable it to start automatically at system boot.

  2. # systemctl start nginx
    # systemctl enable nginx
    # systemctl status nginx

Configure firewalld to Allow Nginx Traffic
  1. By default, CentOS 7 and RHEL 7 built-in firewall is set to block Nginx traffic. To allow web traffic on Nginx, update the system firewall rules to permit inbound packets on HTTP and HTTPS using the commands below.

  2. # firewall-cmd --zone=public --permanent --add-service=http
    # firewall-cmd --zone=public --permanent --add-service=https
    # firewall-cmd --reload

Test Nginx Server on CentOS 7 and RHEL 7
  1. Now you can verify Nginx server by going to the following URL, a default nginx page will be shown.

  2. http://SERVER_DOMAIN_NAME_OR_IP

    You can also use the curl command to get same info using the cli:

    $ curl -I http://10.21.136.13
    $ curl http://10.21.136.13

Nginx Important Files and Directories
  • The default server root directory (top level directory containing configuration files): /etc/nginx.
  • The main Nginx configuration file: /etc/nginx/nginx.conf.
  • Server block (virtual hosts) configurations can be added in: /etc/nginx/conf.d.
  • The default server document root directory (contains web files): /usr/share/nginx/html.



Kamis, 04 Juli 2019

Changing DNS Search Order


Changing DNS Search Order

 

/etc/nsswitch.conf


Open /etc/nsswitch.conf file using text editor:

# vi /etc/nsswitch.conf

Look for hosts:

hosts: files dns mdns4

Set above order as per your requirement. Close and save the file.

host.conf – resolver configuration file


The file /etc/host.conf contains configuration information specific to the resolver library. It should contain one configuration keyword per line, followed by appropriate configuration information.

Open /etc/host.conf file

# vi /etc/host.conf

Find order line which specifies how host lookups are to be performed. It should be followed by one or more lookup methods, separated by commas. Valid methods are bind (dns server), hosts (/etc/hosts file), and nis (old method).

order hosts,bind
Save and close the file.


conclusion

 

The file /etc/nsswitch.conf will let you reconfigure the order of the name resolution. By default, the host file is the first, then the configured DNS. There could be more options.
The file /etc/hosts only lists IP addresses and hostnames (multiple names for one IP if you want) The file /etc/resolv.conf will list the default search domains, and will also list in sequence the name servers to use.