How to install Nginx Config setup in Centos:

From PheonixSolutions
Jump to navigation Jump to search

how to install Nginx Config setup in Centos

Introduction

By default, Nginix HTTP server listens for incoming connection and binds on port 80.

For RHEL and centos-based contribution /etc/nginix/nginx.conf file.

Step 1:

Adding Nginx Repository:

 sudo yum install epel-release

Step 2:

To install nginix repository, in our server.

 sudo yum install nginx

Step 3: To Start Nginx

 sudo systemctl start nginx

Nginix setup will not get started as default the apache webserver is running on our server.

Step 4: To Make changes in a listening port to default_server:

To change the listen default_server to 8080 port.

Enter in to the nginix configuration directory, using

  nano /etc/nginx/nginx.conf, to do changes in the listening server.

Uses of 8080 port:

By default, it will be 80, we can change in to another port.

 8080 port is used to host an alternate web server and it is a proxy and caching port.
 It is a popular alternate to port 80. It used to convey HTTP traffic.

I have changed the listen port

From 80 to 8080


Above, Changed 80 port into 8080 as a default_server.

Step 5: Sudo systemctl restart nginx

After altering nginx port, Restart the nginx web server to bind in our centos Linux environment.

Step 6: see the status of network with netstat or ss command. Here port 8080 must display in the network table.

Step 7: Installing a policycoreutils package.

Add the rules required by SElinux for nginx to bind on the new port.

Some Important requirements For SELinux to enable it.

SELinux has to be enabled , if it is disabled.

This entry can contain one of three values:

 enforcing

SELinux security policy is enforced.

 permissive

SELinux logs warnings instead of enforcing the policy (i.e. the action is allowed to proceed).

 disabled

No SELinux policy is load

Note that this configures the global SELinux enforcement mode. It is still possible to have domains running in permissive mode and/or object managers running as disabled, permissive or enforcing, when the global mode is enforcing or permissive.

REF :https://linuxhint.com/how-to-disable-selinux-on-centos-7/

To check the current status & mode of SELinux:

As you can see in the screenshot below, the orange marked section says SELinux status is enabled. The green marked section says that the Current mode is enforcing.

To alter the enforce, permissive and disable by using this config files.

We have to reboot after every changes done while enabled, disabled and permissive.

But don’t reboot for any reason, it will create more problems.

Step 8: Semanage

yum install policycoreutils

 semanage port -a -t http_port_t -p tcp 8080
 semanage port -m -t http_port_t -p tcp 8080

Step 9: Finally restart the service. And check the status in the network table.

 systemctl restart nginx.service
 netstat -tlpn| grep nginx
 ss -tlpn| grep nginx

Step 10:

 http://sever.ip:8080