Configure Nginx web server
Posted By : Kamaldeep Singh | 31-Dec-2015
NGINX is a free, open-source, high-performance HTTP server which is designed to deliver large amounts of static content quickly with efficiently. Nginx uses an asynchronous and scalable event-driven model which provides more predictable performance under load. But before proceeding further, I would like you to know about installation.
Installing NGINX:-
The simplest way to install Nginx in Ubuntu is by downloading it from Debian’s repositories. Run the following command in terminal to install NGINX
sudo apt-get install nginx
After successful installation, you can loacte the NGINX files in the "/etc/nginx/" directory. The primary configuration file is "/etc/nginx/nginx.conf"
Now before proceeding further, let me tell you about some of the basic commands.
- sudo service nginx start To start the NGINX server.
- sudo service nginx stop To stop the NGINX server.
- sudo service nginx restart To restart the NGINX server.
- sudo nginx -t To test the NGINX configuration for syntax errors.
Now you’re ready to make changes to your Nginx configuration. Whenever you make a change to the nginx.conf file, you need to reload your configuration before the change will take effect.
Here is the sample code which I will explain.
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.html; } }
- server Tells this is the start of server configuration.
- listen Tells Nginx the hostname/IP and the TCP port where it should listen user requests for HTTP connections. By default, Nginx will listen on port 80 for HTTP connections
- root This describes where is the path to the project files. In the above example, the index.htm is saved in /usr/share/nginx/html/index.html
- index Tells Nginx which file to serve if none is specified
- server_name The domain name is specified in the server_name variable
- location Tells Nginx what to respond to requests for resources within the server
THANKS
So this was all about NGINX installation and configuration. Hope this thing works. For detailed information, visit the following link https://www.nginx.com/resources/wiki/
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Kamaldeep Singh
Kamaldeep is a highly skilled Backend Developer specializing in Java, specifically the Spring framework. He also has extensive knowledge of Javascript and associated frameworks such as Node.js and Express. He possesses a deep understanding of the latest technologies and has hands-on experience with Core Java, Spring Boot, Hibernate, Apache Kafka messaging queue, Redis, as well as both relational databases like MySQL and PostgreSQL and non-relational databases like MongoDB. He has made significant contributions to various projects, including Viral Nation, ExamWorks, TNIBRO, Biogas engineering, SecureNow - Web Application, FB Messenger Chatbot, Dialogflow Chatbot, and Catalyst. Kamaldeep's expertise allows him to seamlessly integrate different technologies into applications, highlighting his adaptability and innovative mindset. His practical experience and strong technical skills make him an invaluable asset to any team.