How to configure Nginx in Linux?
Before going to the configuration of Nginx here is the information on what is Nginx software is? Nginx is an open source web server and it can also be used as a reverse proxy server. Nginx is a high-performance web server where it can handle the load of some large and busiest websites on the internet. Using Nginx is very good at handling many concurrent connections and excels at serving static content.
Today Nginx is one of the powerful tools, and its configuration can be intimidating for those coming from other servers, or if you are new to web servers. Nginx is an open source web server that is similar to Apache, but very lightweight. Nginx works as both web server and reverses proxy server.
Below are some of the features of Nginx :
>> HTTP basic authentication
>> It serves static and index files
>> Supports XSLT, gzip, SSI and image resizing filters
>> Both name-based and IP-based virtual server can be configured
>> Simple load balancing with fault tolerance
>> Supports SSL
>> Supports rewrite module
>> Reverse proxy with caching
>> All the main mail proxy server features are supported
Here is the information on configuring Nginx in Linux servers:
1. Install Nginx
To configure the Nginx software on your server you need to login to your SSD and run the below command to install Nginx on your server.
yum -y install nginx
2. Change the Default Nginx Listen Port
Once after installing the Nginx software on your server, you need to change the default Nginx listen port. Most of the time when you install Nginx it will default configured to port 80. And if you installing Nginx on a machine where it is already installed with Apache running server then you should change the Nginx listen port. You can follow the below step to change the default Nginx listens port.
Here you also need to check that is there any service is running on 80 Port by using the following commandlsof -i:80
If any service is running under 80, kill the service by using this command,
kill -9 $(lsof -t -i:80)
In the server section of nginx .conf, change the port to 80,
3. Start Your Nginx Server
Once after changing the default, Nginx listen port, you need to start your Nginx server by using the below command.
service nginx start
4. Stop The Nginx Server
And at some point, if you want to stop the Nginx and use any other web server then you can make changes without any issues. So if you want to stop the Nginx server then follow the below command.
service nginx stop