NGINX Cheat Sheet 1 - Basics

NGINX Cheat Sheet 1 - Basics

$ sudo yum update
$ sudo yum install nginx        

Installing nginx on RedHat/CentOS.

$ sudo apt update
$ sudo apt install nginx        

Installing nginx on Debian/Ubuntu.

$ systemctl enable nginx
$ systemctl start nginx        

Adding nginx to startup services and start it, using systemctl service manager.

$ nginx -v        

Shows nginx version and also an easy way to verifying your installation.

$ nginx -h        

Shows nginx help menu.

$ nginx -t        

Tests your nginx configuration files.

$ nginx -T        

Tests your nginx configuration files and prints validated configuration.

$ nginx -s stop        

Sends stop signal to nginx and stopping it immediately.

$ nginx -s quit        

Sends quit signal to nginx and stopping it after it finishes pending requests.

$ nginx -s reload        

Sends reload signal to nginx and reloading configurations without interrupting pending requests.

$ nginx -s reopen        

Sends reopen to nginx to reopen a new log file without disrupting the server's operation.


NGINX Files and Directories

/etc/nginx/ : NGINX default configuration directory.

/etc/nginx/nginx.conf : Default NGINX configuration file and entry point. this file includes global settings like logging and loading dynamic modules.

/etc/nginx/conf.d/ : This directory contains other server configuration files ending with .conf. By default these files included within the /etc/nginx/nginx.conf file in the top level http block. It's best practice to utilize include statement and organize your configurations files in this way.

/var/log/nginx/ : This is nginx default log location. This directory includes access.log and error.log files. The first file contains request logs and error file contains error events and debug information.


Serving Static Content

server {
??? listen 80 default_server;
??? server_name website.com;

??? location / {
??????? root /usr/share/nginx/html;
??????? index index.html index.htm;
??? }
}        

Here's a simple configuration file, serving static content on port 80 from /usr/share/nginx/html directory. The first line defines a new server block and nginx will listen on specified port for this new server. The default_server parameter instructs nginx to use this server as the default server for port 80. server_name parameter instructs nginx to only respond to the requests with the website.com domain name. location block defines the configuration for the path "/", which is the root directory of the website and root parameter specifies the root directory where the static files located, so nginx will look for static files in this directory and lastly, index parameter specifies index file that nginx should look for, when the "/" path requested. in this case if index.html file not found, nginx attempt to server the second file which is index.htm.

Alireza Nourkazemi

App & Web Developer / Vulnerability researcher

1 年

??

Reza Hosseinzadeh

full stack web developer (react | node)

1 年

Awesome ??

要查看或添加评论,请登录

Rouzbeh Sabzehei的更多文章

社区洞察

其他会员也浏览了