国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home System Tutorial LINUX How to Compile and Install NGINX from Sources in Linux

How to Compile and Install NGINX from Sources in Linux

Jun 21, 2025 am 09:45 AM

Nginx is the fastest growing Webserver today on public internet-facing servers due to its free open-source modular model, high performance, stability, simple configurations files, asynchronous architecture (event-driven), and low resources needed to run.

This tutorial will guide you on installing the latest stable version of Nginx on RHEL-based distributions from sources because official system repositories don’t provide a binary package.

If you want to avoid sources installation you can add an official Nginx repository and install the binary package with the help of the yum or dnf package manager as shown:

Table of Contents

Method 1: Install NGINX Using Yum Repository

Before you install nginx, you need to enable the nginx packages repository on RHEL and its derivatives such as CentOS, Rocky Linux, AlmaLinux, and Oracle Linux. Afterward, you can install and update nginx from the repository.

First, install the yum-utils package as shown.

# yum install yum-utils

To enable the nginx official yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

How to Compile and Install NGINX from Sources in Linux

Next, you can install and update nginx from the repository.

# yum install nginx

How to Compile and Install NGINX from Sources in Linux

Important: Please note, following the above official nginx yum repositories will give you an older version of nginx, if you really want to build the most recent version of Nginx, then I suggest you follow the source installation as shown below.

Using sources compilation and installation has some benefits because you can install the latest version available, you can tweak Nginx configuration by adding or removing modules, and change the installation system path, or other important settings, in other words, you have complete control over the installation process.

Method 2: Compiling and Installing NGINX from Source

Before starting the Nginx compilation and installation process make sure that you have a C/C compiler, PCRE (Perl Compatible Regular Expressions), Zlib Compression Library, and OpenSSL (if you intend to run Nxing with SSL support) packages installed on your machine by issuing the following command.

# yum -y install gcc gcc-c   make zlib-devel pcre-devel openssl-devel

How to Compile and Install NGINX from Sources in Linux

Download Nginx Source

Now, go to the Nginx download page and grab the latest stable version of the Nginx source tarball using the following wget command, then extract the nginx archive and move into Nginx extracted directory as shown.

# wget http://nginx.org/download/nginx-1.23.4.tar.gz
# tar xfz nginx-1.23.4.tar.gz 
# cd nginx-1.23.4
# ls -all

How to Compile and Install NGINX from Sources in Linux

Compile Nginx from Source

The next step is to customize the Nginx installation process using the configure file to visualize configuration options and modules needed for the Nginx compilation process using the following command.

# ./configure --help

How to Compile and Install NGINX from Sources in Linux

Now it’s time to compile Nginx with your specific configurations and enabled or disabled modules. For this tutorial, the following modules and specifications were used, but you can tweak the compilation to whatever suits your needs.

  • --user=nginx – set the system user that Nginx will run as.
  • --group=nginx – set the system group that Nginx will run as.
  • --prefix=/etc/nginx – directory for server files (nginx.conf file and other configuration files) – default is /usr/local/nginx directory.
  • --sbin-path=/usr/sbin/nginx – Nginx executable file location.
  • --conf-path=/etc/nginx/nginx.conf – sets the name for the nginx.conf configuration file – you can change it.
  • --error-log-path=/var/log/nginx/error.log – sets Nginx error log file location.
  • --http-log-path=/var/log/nginx/access.log – sets Nginx access log file location.
  • --pid-path=/var/run/nginx.pid – sets the name for the main process ID file.
  • --lock-path=/var/run/nginx.lock – sets the name for the Nginx lock file.
  • --with-http_ssl_module – enables building the HTTPS module – not built by default and requires an OpenSSL library.
  • --with-pcre – sets the path to the sources of the PCRE library – not built by default and requires a PCRE library.

To view, a list of all Nginx modules visit the Nginx docs web page at http://wiki.nginx.org/Modules.

If you don’t need a specific module installed on Nginx you can disable it using the following command.

--without-module_name

Now start to compile Nginx by issuing the following command, which will use all the configurations and modules discussed above (make sure the command stays on a single line).

# ./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-http_ssl_module --with-pcre

How to Compile and Install NGINX from Sources in Linux

After the compilation process verifies all system-required utilities like GNU C compiler, PCRE, and OpenSSL libraries, it creates the make.conf file and outputs a summary of all configurations.

Nginx Compilation Summary
Configuration summary
    using system PCRE2 library
    using system OpenSSL library
    using system zlib library

  nginx path prefix: "/etc/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/etc/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

Build Nginx from Source

The last step is to build the binaries using make command, which can take some time to finish depending on your machine resources, and install Nginx on your system with make install command.

Be careful that the make install command requires root privileges to perform the installation, so if you’re not logged in with a root account use a privileged user with sudo.

# make
# make install

After the installation process has finished with success, add the nginx system user (with /etc/nginx/ as his home directory and with no valid shell), the user that Nginx will run as by issuing the following useradd command.

# useradd -d /etc/nginx/ -s /sbin/nologin nginx

How to Compile and Install NGINX from Sources in Linux

Configure Nginx File

While compiling, we had specified that Nginx will run from the nginx system user, open nginx.conf file and change the user statement to nginx.

# nano /etc/nginx/nginx.conf
OR
# vi /etc/nginx/nginx.conf

Here locate and change the user and, also, document root location statements, with the following options.

user nginx;
location / {
                root /var/www/html;
                autoindex on;
                index index.html index.htm;

How to Compile and Install NGINX from Sources in Linux

Before starting Nginx, assure that you have created the web document root path, then start nginx using the following command.

# mkdir -p /var/www/html
# /usr/sbin/nginx

If you want to check if Nginx is running using your shell prompt, run the netstat command to verify TCP connection.

# netstat -tulpn | grep nginx

How to Compile and Install NGINX from Sources in Linux

Open Nginx on Firewalld

To verify Nginx from a remote system, add a Firewall rule to open connection to outside on Port 80 and 443.

# firewall-cmd --permanent --add-service=http
# firewall-cmd --permanent --add-service=https
# systemctl restart firewalld

Finally, open a browser, and direct the URL to your server IP Address at:

http://server_IP

How to Compile and Install NGINX from Sources in Linux

Manage Nginx Service

To manage the Nginx process use the following commands.

# /usr/sbin/nginx -V         [show Nginx modules and configurations]
# /usr/sbin/nginx -h         [help options]
# /usr/sbin/nginx -t         [check configuration file]
# /usr/sbin/nginx            [start Nginx process]
# /usr/sbin/nginx -s stop    [stop Nginx process]
# /usr/sbin/nginx -s reload  [reload Nginx process]

How to Compile and Install NGINX from Sources in Linux

If you need to manage the Nginx daemon process through a systemd script, create the following file on /lib/systemd/system/nginx.service, and, then, you can use systemctl commands to manage the process.

# vi /lib/systemd/system/nginx.service

Add the following file content.

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

After the Nginx systemd file is created, manage the daemon using the below commands.

# systemctl start nginx
# systemctl stop nginx
# systemctl status nginx

That’s all! Now you have the latest version of Nginx installed on your RHEL-based distributions. In the next tutorial, I will discuss how to install and enable the PHP-FPM process manager through Nginx FastCGI Gateway.

The above is the detailed content of How to Compile and Install NGINX from Sources in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

5 Best Open Source Mathematical Equation Editors for Linux 5 Best Open Source Mathematical Equation Editors for Linux Jun 18, 2025 am 09:28 AM

Are you looking for good software to write mathematical equations? If so, this article provides the top 5 equation editors that you can easily install on your favorite Linux distribution.In addition to being compatible with different types of mathema

SCP Linux Command – Securely Transfer Files in Linux SCP Linux Command – Securely Transfer Files in Linux Jun 20, 2025 am 09:16 AM

Linux administrators should be familiar with the command-line environment. Since GUI (Graphical User Interface) mode in Linux servers is not commonly installed.SSH may be the most popular protocol to enable Linux administrators to manage the servers

Gogo - Create Shortcuts to Directory Paths in Linux Gogo - Create Shortcuts to Directory Paths in Linux Jun 19, 2025 am 10:41 AM

Gogo is a remarkable tool to bookmark directories inside your Linux shell. It helps you create shortcuts for long and complex paths in Linux. This way, you no longer need to type or memorize lengthy paths on Linux.For example, if there's a directory

What is a PPA and how do I add one to Ubuntu? What is a PPA and how do I add one to Ubuntu? Jun 18, 2025 am 12:21 AM

PPA is an important tool for Ubuntu users to expand their software sources. 1. When searching for PPA, you should visit Launchpad.net, confirm the official PPA in the project official website or document, and read the description and user comments to ensure its security and maintenance status; 2. Add PPA to use the terminal command sudoadd-apt-repositoryppa:/, and then run sudoaptupdate to update the package list; 3. Manage PPAs to view the added list through the grep command, use the --remove parameter to remove or manually delete the .list file to avoid problems caused by incompatibility or stopping updates; 4. Use PPA to weigh the necessity and prioritize the situations that the official does not provide or require a new version of the software.

Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Install LXC (Linux Containers) in RHEL, Rocky & AlmaLinux Jul 05, 2025 am 09:25 AM

LXD is described as the next-generation container and virtual machine manager that offers an immersive for Linux systems running inside containers or as virtual machines. It provides images for an inordinate number of Linux distributions with support

How to create a file of a specific size for testing? How to create a file of a specific size for testing? Jun 17, 2025 am 09:23 AM

How to quickly generate test files of a specified size? It can be achieved using command line tools or graphical software. On Windows, you can use fsutilfilecreatenew file name size to generate a file with a specified byte; macOS/Linux can use ddif=/dev/zeroof=filebs=1Mcount=100 to generate real data files, or use truncate-s100M files to quickly create sparse files. If you are not familiar with the command line, you can choose FSUtilGUI, DummyFileGenerator and other tool software. Notes include: pay attention to file system limitations (such as FAT32 file size upper limit), avoid overwriting existing files, and some programs may

How to install Linux alongside Windows (dual boot)? How to install Linux alongside Windows (dual boot)? Jun 18, 2025 am 12:19 AM

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

NVM - Install and Manage Multiple Node.js Versions in Linux NVM - Install and Manage Multiple Node.js Versions in Linux Jun 19, 2025 am 09:09 AM

Node Version Manager (NVM) is a simple bash script that helps manage multiple Node.js versions on your Linux system. It enables you to install various Node.js versions, view available versions for installation, and check already installed versions.NV

See all articles