{"id":23961065,"url":"https://github.com/tawounfouet/nginx-complete-training","last_synced_at":"2026-06-23T15:33:09.329Z","repository":{"id":169861444,"uuid":"645934322","full_name":"tawounfouet/nginx-complete-training","owner":"tawounfouet","description":"NGINX Websever | Reverse Proxy | Load Balancer | SSL Certificates","archived":false,"fork":false,"pushed_at":"2023-05-27T00:31:14.000Z","size":222,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-15T20:39:31.770Z","etag":null,"topics":["caching","load-balancer","nginx","reverse-proxy","shell-scripting","ssl-certificates","vagrantfile","webserver"],"latest_commit_sha":null,"homepage":"https://www.youtube.com/watch?v=NwijBVfiK_o\u0026t=20033s","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tawounfouet.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-26T19:48:26.000Z","updated_at":"2023-07-18T09:29:16.000Z","dependencies_parsed_at":"2023-07-14T15:17:03.566Z","dependency_job_id":null,"html_url":"https://github.com/tawounfouet/nginx-complete-training","commit_stats":null,"previous_names":["tawounfouet/nginx-comple-traing"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tawounfouet/nginx-complete-training","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tawounfouet%2Fnginx-complete-training","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tawounfouet%2Fnginx-complete-training/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tawounfouet%2Fnginx-complete-training/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tawounfouet%2Fnginx-complete-training/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tawounfouet","download_url":"https://codeload.github.com/tawounfouet/nginx-complete-training/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tawounfouet%2Fnginx-complete-training/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34696897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","load-balancer","nginx","reverse-proxy","shell-scripting","ssl-certificates","vagrantfile","webserver"],"created_at":"2025-01-06T19:59:19.827Z","updated_at":"2026-06-23T15:33:09.310Z","avatar_url":"https://github.com/tawounfouet.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"## NGINX | Webserver | Reverse Proxy | Load Balancer | SSL \n\nNGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption. \n\nNGINX is one of a handful of servers written to address the C10K problem. Unlike traditional servers, NGINX doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load.\n\nEven if you don’t expect to handle thousands of simultaneous requests, you can still benefit from NGINX’s high-performance and small memory footprint. NGINX scales in all directions: from the smallest VPS all the way up to large clusters of servers.\n\n\n### Install NGINX on Ubuntu 18.04\n\n```bash\nsudo apt update # apt stands for Advanced Packaging Tool\nsudo apt-get update # apt-get is a command line tool for handling packages and updates in Ubuntu\nsudo apt install nginx\n```\n\nGrant sudo access to the vagrant user\n```bash\nsudo usermod -aG sudo vagrant\n```\n\nGet IP address of the server\n```bash\nip addr show eth1 | grep inet | awk '{ print $2; }' | sed 's/\\/.*$//'\n\nifconfig\nifconfig enp0s8 | grep inet | awk '{ print $2; }' | sed 's/\\/.*$//'\n```\n\n\nCheck if NGINX process is running\n```bash\nps aux | grep nginx\n\n# results\nvagrant@nginx-web-server:/etc$ ps aux | grep nginx\nroot      3125  0.0  0.3 141132  1552 ?        Ss   12:52   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;\nwww-data  3126  0.0  1.2 143804  6148 ?        S    12:52   0:00 nginx: worker process\nvagrant   3218  0.0  0.2  14860  1064 pts/0    S+   12:53   0:00 grep --color=auto nginx\n```\nWe can see that two process are running for NGINX (one as `root` and one as `www-data` user).\n - the master process is running as root. \n - The worker process is running as www-data user. \nSo nginx by default create a master process as root and worker process as www-data user. \n\nVie the status of NGINX\n```bash\nsystemctl status nginx\n```\n\n### NGINX Configuration Files\n\nNGINX has one master process and several worker processes. The main configuration file is usually called `nginx.conf`. The default location for the configuration file is `/etc/nginx/nginx.conf`.\n```bash\n# To go to the directory (view configuration file)\nls -l /etc/nginx\n\n# results\ntotal 64\ndrwxr-xr-x 2 root root 4096 Nov 10  2022 conf.d\n-rw-r--r-- 1 root root 1077 Apr  6  2018 fastcgi.conf\n-rw-r--r-- 1 root root 1007 Apr  6  2018 fastcgi_params\n-rw-r--r-- 1 root root 2837 Apr  6  2018 koi-utf\n-rw-r--r-- 1 root root 2223 Apr  6  2018 koi-win\n-rw-r--r-- 1 root root 3957 Apr  6  2018 mime.types\ndrwxr-xr-x 2 root root 4096 Nov 10  2022 modules-available\ndrwxr-xr-x 2 root root 4096 May 26 12:52 modules-enabled\n-rw-r--r-- 1 root root 1482 Apr  6  2018 nginx.conf\n-rw-r--r-- 1 root root  180 Apr  6  2018 proxy_params\n-rw-r--r-- 1 root root  636 Apr  6  2018 scgi_params\ndrwxr-xr-x 2 root root 4096 May 26 12:52 sites-available\ndrwxr-xr-x 2 root root 4096 May 26 12:52 sites-enabled\ndrwxr-xr-x 2 root root 4096 May 26 12:52 snippets\n-rw-r--r-- 1 root root  664 Apr  6  2018 uwsgi_params\n-rw-r--r-- 1 root root 3071 Apr  6  2018 win-utf\n```\n\nThe `nginx.conf` file contains a number of directives that affect how NGINX will work. The `nginx.conf` file is read each time the NGINX server starts, so you need to restart the NGINX server each time you make a configuration change.\n```bash\ncat /etc/nginx/nginx.conf # from the home directory\ncat nginx.conf # from the nginx directory\n\n```\n\nAcces log folder\n```bash\ncd /var/log/nginx\n\n# results\n#vagrant@nginx-web-server:/var/log/nginx$ ls\naccess.log  error.log\n\n#vagrant@nginx-web-server:/var/log/nginx$ ls -l\ntotal 0\n-rw-r----- 1 www-data adm 0 May 26 12:52 access.log\n-rw-r----- 1 www-data adm 0 May 26 12:52 error.log\n\n#vagrant@nginx-web-server:/var/log/nginx$ tail -f *\ntail: cannot open 'access.log' for reading: Permission denied\ntail: cannot open 'error.log' for reading: Permission denied\ntail: no files remaining\n\n# Grant permission for access.log and error.log to vagrant user\nsudo chown vagrant:adm access.log error.log\n\n\n#vagrant@nginx-web-server:/var/log/nginx$ sudo chown vagrant:adm access.log error.log\n#vagrant@nginx-web-server:/var/log/nginx$ tail -f *\n==\u003e access.log \u003c==\n\n==\u003e error.log \u003c==\n```\nGet the ipd address of the server and access the server from the browser\n```bash\nip addr show enp0s8 | grep inet | awk '{ print $2; }' | sed 's/\\/.*$//' # get the ip address of the server\n```\nWith the ip address, access the server from the browser and check the access.log file\n```bash\ncurl 192.168.200.10\n\n# Access the log file\ntail -f /var/log/nginx/access.log\n\n# from the log directory\ntail -f * # this will show the access.log file\n```\n\nUninstall NGINX\n```bash\nsudo apt-get remove nginx nginx-common # remove nginx and nginx-common\nsudo apt-get purge nginx nginx-common # remove nginx and nginx-common\nsudo apt-get autoremove # remove unused packages\n```\n\n\n\n### NGINX Installation on CentOS 7/8\n\nCentos have the yum package manager. Yum is a package manager that is used to install, update and remove packages in CentOS and Red Hat distributions. Yum is a front-end tool for rpm that automatically solves dependencies for packages. Yum is used to install, update, delete and search packages.\n\n```bash\nsudo yum update # update the package manager\nyum install nginx # install nginx\n```\n\nCheck if NGINX is running\n```bash\nps aux | grep nginx\n\n# results\n#[root@client2 vagrant]# ps aux | grep nginx\nroot     25023  0.0  0.1 112828   976 pts/0    R+   13:31   0:00 grep --color=auto nginx\n```\nWe can see that no process is running for NGINX. This is because NGINX is not running. We need to start NGINX\n```bash\nsudo systemctl start nginx # start nginx\nsudo systemctl status nginx # check the status of nginx\nsudo systemctl enable nginx # enable nginx to start at boot\nsudo systemctl stop nginx # stop nginx\n```\n\nCheck for the status of NGINX again\n```bash\n#[root@client2 vagrant]# ps aux | grep nginx\nroot     25037  0.0  0.1  39304   940 ?        Ss   13:32   0:00 nginx: master process /usr/sbin/nginx\nnginx    25039  0.0  0.3  39696  1820 ?        S    13:32   0:00 nginx: worker process\nroot     25052  0.0  0.1 112828   976 pts/0    R+   13:33   0:00 grep --color=auto nginx\n```\n\n\n### NGINX Installation from Source code binary both on CentOS 7/8 and Ubuntu 18/20\n\nWhen we are install nginx from the package manager, we can not include the modules in nginx. We can only include the modules when we install nginx from the source code. \n- We can't add the custom modules to the nginx \n- We can't the third party modules to the nginx \nTo include these modules, we need to install nginx from the source code. \n\n```bash\n\n# Download the source code - Mainline version : https://nginx.org/en/download.html \n#wget http://nginx.org/download/nginx-1.20.0.tar.gz\nwget https://nginx.org/download/nginx-1.25.0.tar.gz\n\n# On centos we need to first install wget before we can use it\nsudo yum install wget\n\n# Extract the source code\ntar -xvf nginx-1.25.0.tar.gz\n\n# cd into the directory and run the configure script - to build the nginx binary with the modules ()\ncd nginx-1.25.0\n./configure \n./configure --help # this will show the help options\n#vagrant@nginx-web-server:~/nginx-1.25.0$ ./configure\nchecking for OS\n + Linux 4.15.0-210-generic x86_64\nchecking for C compiler ... not found\n./configure: error: C compiler cc is not found\n\n# To compile the nginx source code, we need to install some compiler - the gcc compiler\nsudo apt-get install gcc # install gcc compiler\n\nsudo yum install gcc\nsudo yum group install \"Development Tools\" # this will install the gcc compiler and other tools\n\n# Install the dependencies\n#sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev\n\n# run the configure script again\n./configure\n\n# the installation fail again - failed to detect PCRE library\n./configure: error: the HTTP rewrite module requires the PCRE library.\nYou can either disable the module by using --without-http_rewrite_module\noption, or install the PCRE library into the system, or build the PCRE library\nstatically from the source with nginx by using --with-pcre=\u003cpath\u003e option.\n```\nNote that nginx comes with two kind of libraries (modules), one is in build modules and the other one is third party modules. \n- The in build modules are the modules that comes with the nginx source code. \n- The third party modules are the modules that are not included in the nginx source code. We need to install them separately. \n\n```bash\n# Install the PCRE library - this is the in build module\nsudo apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev make # install the PCRE library\nsudo yum install pcre-devel zlib-devel openss openssl-devel make  # install the PCRE library\n\n# run the configure script once again\n./configure\n\n# Now the installation is successful\n```\n\nWe can now build the nginx binary\nhttps://nginx.org/en/docs/configure.html \n```bash\n# build the nginx binary\n./configure --sbin-path=/usr/bin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-pcre --with-http_ssl_module\n\n# a make file is created after the configure script is run\n\n# Build the nginx binary - to compile the nginx source code\nmake # this will build the nginx binary\n\n# Install the nginx binary - to install the nginx binary wihch we built from the source code\nsudo make install # this will install the nginx binary\n```\n$ nginx -V # this will show the nginx version and the modules that are included in the nginx binary\n`$\n\nFinally, we nginx is successfully installed from the source code. We can now start nginx\n```bash\n# Start nginx\nsudo nginx\n\n# process running\nps aux | grep nginx\nps -ef | grep nginx\n```\n\n#### Add NGINX as a service on Ubuntu 18/20 and CentOS 7/8\n\nThe question is why to we want to add nginx as a service on the server (on the operating system) ?\n- We want to start nginx automatically when the server boots up\n- We want to stop nginx automatically when the server shuts down\n- We want to restart nginx automatically when the server restarts\n- We want to reload nginx automatically when the server reloads\n- We want to enable nginx to start automatically when the server boots up\n- We want to disable nginx to start automatically when the server boots up\n- We want to check the status of nginx\n- We want to check the nginx configuration file\n- We want to check the nginx error log file\n- We want to check the nginx access log file\n- We want to check the nginx process id\n- We want to check the nginx version\n- We want to check the nginx modules\n- We want to check the nginx configuration file syntax\n- We want to check the nginx configuration file syntax and test it\n\nSo we need to add `NGINX` as a systemd service on the server. \n\nFirst we need to understand what is `systemd` ? and what are the services in `UNIX` and unix base system ?\n\n`systemd` is a system and service manager for Linux operating systems. It is designed to be backwards compatible with SysV init scripts, and provides a number of features such as parallel startup of system services at boot time, on-demand activation of daemons, support for system state snapshots, or dependency-based service control logic.\n    Systemd process will help us to make the process more resilient and robust. This means that if the process fails, it will automatically restart the process. \n\n\n\n\n\nThe unix base system is a collection of programs that are used to manage the system. These programs are called services.\n- The services are the programs that are used to manage the system\n- The services are the programs that are used to manage the system resources\nSome services are :\n- The `systemd` service is used to manage the system\n- The `nginx` service is used to manage the nginx web server\n- The `mysql` service is used to manage the mysql database server\n- The `php-fpm` service is used to manage the php-fpm server\n- The `php` service is used to manage the php server\n- The `apache` service is used to manage the apache web server\n- The `httpd` service is used to manage the apache web server\n- The `redis` service is used to manage the redis server\n- The `memcached` service is used to manage the memcached server\n- The `mongodb` service is used to manage the mongodb server\n- The `postgresql` service is used to manage the postgresql server\n- The `jenkins` service is used to manage the jenkins server\n- The `docker` service is used to manage the docker server\n- The `kubernetes` service is used to manage the kubernetes server\n- The `gitlab` service is used to manage the gitlab server\n\n\n\n\nLet's now see how to add nginx as a service on the server.\n```bash\n# first reboot the server\nsudo reboot \n```\nThe process got kill after the reboot of the server. We need to start the nginx process again\n```bash\n# Start nginx\nsudo nginx\n```\n\nThe process is running again. But we want to start nginx automatically when the server boots up. So we need to add nginx as a service on the server. \nfor how service to be more resilient and robust, we need to add the nginx process as a service on the server. \n```bash\n\n# Create a service file for nginx - https://www.nginx.com/resources/wiki/start/topics/examples/systemd/ \n#sudo vim /etc/systemd/system/nginx.service\n#sudo touch /lib/systemd/system/nginx.service\nsudo vi /lib/systemd/system/nginx.service\n\n# Add the following content to the nginx.service file\n[Unit]\nDescription=The NGINX HTTP and reverse proxy server\nAfter=syslog.target network-online.target remote-fs.target nss-lookup.target\nWants=network-online.target\n\n[Service]\nType=forking\nPIDFile=/run/nginx.pid\nExecStartPre=/usr/sbin/nginx -t\nExecStart=/usr/sbin/nginx\nExecReload=/usr/sbin/nginx -s reload\nExecStop=/bin/kill -s QUIT $MAINPID\nPrivateTmp=true\n\n[Install]\nWantedBy=multi-user.target\n```\n\nLet's do some changes to the nginx.service file\n```bash\n[Unit]\nDescription=The NGINX HTTP and reverse proxy server\nAfter=syslog.target network-online.target remote-fs.target nss-lookup.target\nWants=network-online.target\n\n[Service]\nType=forking\nPIDFile=/var/run/nginx.pid\nExecStartPre=/usr/bin/nginx -t\nExecStart=/usr/bin/nginx\nExecReload=/usr/sbin/nginx -s reload\nExecStop=/bin/kill -s QUIT $MAINPID\nPrivateTmp=true\n\n[Install]\nWantedBy=multi-user.target\n```\n\nLet's now start nginx once again\n```bash\n# Start nginx se\nsudo nginx\n\nnginx -V # this will show the nginx version and the modules that are included in the nginx binary\nnginx -h # this will show the help menu\nnginx -t # this will test the nginx configuration file\nnginx -s stop # this will stop the nginx process\n\nps -ef | grep nginx # this will show the nginx process\n\nsudo systemctl status nginx # this will show the nginx process\nsudo systemctl start nginx # this will start the nginx process\nsudo systemctl stop nginx # this will stop the nginx process\nsudo systemctl restart nginx # this will restart the nginx process\nsudo systemctl enable nginx # this will enable the nginx process to start automatically when the server boots up\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftawounfouet%2Fnginx-complete-training","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftawounfouet%2Fnginx-complete-training","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftawounfouet%2Fnginx-complete-training/lists"}