[2] Nginx Server Setup - Downloading and Setting Up a Specific Version of Nginx
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
Instead of installing Nginx directly to the system path, this guide explains how to download, build, and set up Nginx manually.
Setup Environment
- Red Hat Enterprise Linux release 9.4 (Plow)
1. Download and Extract Nginx
To download and extract Nginx:
wget http://nginx.org/download/nginx-1.21.6.tar.gz
tar -xvf nginx-1.21.6.tar.gz
To download a different version, simply change the version number in the command and proceed with the steps as outlined.
2. Install Required Libraries
Install essential libraries:
sudo yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
Explanation of each library:
- gcc: The C compiler required to compile Nginx source code into an executable.
- pcre: Provides regular expression handling for Nginx.
- pcre-devel: Contains development headers needed when compiling Nginx.
- zlib: Enables gzip compression in Nginx.
- zlib-devel: Provides zlibs development files needed for compiling.
- openssl: Necessary for SSL/TLS encryption, enabling HTTPS.
- openssl-devel: Includes OpenSSLs development headers, required to compile Nginx with SSL/TLS support.
If you encounter the following error during installation:
Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs) 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository 'rhel-9-for-x86_64-baseos-rpms':
- Curl error (91): SSL server certificate status verification FAILED for https://cdn.redhat.com/content/dist/rhel9/9/x86_64/baseos/os/repodata/repomd.xml [OCSP response has expired]
Error: Failed to download metadata for repo 'rhel-9-for-x86_64-baseos-rpms': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried"
This issue is due to a time discrepancy. To resolve it, run:
systemctl restart chronyd
3. Set Up Paths
Install to the "/root" directory with the following commands:
./configure --prefix=$PWD/build --sbin-path=/root/nginx/sbin/nginx --conf-path=/root/nginx/conf/nginx.conf --error-log-path=/root/nginx/logs/error.log --http-log-path=/root/nginx/logs/access.log --http-client-body-temp-path=/root/nginx/client_body_temp --http-proxy-temp-path=/root/nginx/proxy_temp --http-fastcgi-temp-path=/root/nginx/fastcgi_temp --pid-path=/root/nginx/logs/nginx.pid --lock-path=/root/nginx/logs/nginx.lock
make
make install
3-1. Explanation of Each Configuration Option
1. ./configure --prefix=$PWD/build": Sets the installation directory to a "build" folder in the current directory.
2. --sbin-path=/root/nginx/sbin/nginx": Specifies the path for the "nginx" executable.
3. --conf-path=/root/nginx/conf/nginx.conf": Sets the path for the Nginx configuration file.
4. --error-log-path=/root/nginx/logs/error.log": Sets the error log file path.
5. --http-log-path=/root/nginx/logs/access.log": Specifies the path for the HTTP request log.
6. --http-client-body-temp-path=/root/nginx/client_body_temp": Defines the path for temporary files of client body content.
7. --http-proxy-temp-path=/root/nginx/proxy_temp": Sets the proxy request temporary file storage path.
8. --http-fastcgi-temp-path=/root/nginx/fastcgi_temp": Specifies the FastCGI request temporary file path.
9. --pid-path=/root/nginx/logs/nginx.pid": Sets the process ID file path.
10. --lock-path=/root/nginx/logs/nginx.lock": Defines the lock file path to prevent duplicate runs.
4. Confirm Installation
To confirm the installation:
[root@vbox nginx]# pwd
/root/nginx
[root@vbox nginx]# ll
total 4
drwxr-xr-x. 2 root root 4096 Nov 3 23:47 conf
drwxr-xr-x. 2 root root 6 Nov 3 23:47 logs
drwxr-xr-x. 2 root root 19 Nov 3 23:47 sbin
5. Configure Nginx Server
Set up the configuration as follows:
worker_processes 1024;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
large_client_header_buffers 4 16k;
server {
listen 10099;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
}
6. Run Nginx
Navigate to the sbin directory where Nginx is installed and start it:
cd /root/nginx/sbin
./nginx
To check if it’s running, use: s -ef | grep nginx
Example output:
nobody 44425 43920 0 23:56 ? 00:00:00 nginx: worker process
nobody 44426 43920 0 23:56 ? 00:00:00 nginx: worker process
nobody 44427 43920 0 23:56 ? 00:00:00 nginx: worker process
nobody 44428 43920 0 23:56 ? 00:00:00 nginx: worker process
nobody 44429 43920 0 23:56 ? 00:00:00 nginx: worker process
7. Confirm Accessibility
As this server runs on a VM, you need to configure port forwarding and disable the firewall for access.
7-1. Add Port Forwarding
Example configuration:
7-2. Disable the Firewall
[root@vbox nginx] $ sudo firewall-cmd --permanent --add-port=10099/tcp
success
[root@vbox nginx] $ sudo firewall-cmd --reload
success
8. Verify Functionality
Confirm functionality in the browser.
Accessing Nginx Logs
Example log entries:
10.0.2.2 - - [04/Nov/2024:00:06:21 +0900] "GET / HTTP/1.1" 403 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
10.0.2.2 - - [04/Nov/2024:00:06:22 +0900] "GET /favicon.ico HTTP/1.1" 500 579 "http://127.0.0.1:10099/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
Related Links
- [7] Nging Server Setup - Building a Text Detection API using Drogon Server with OpenCV
- [6] Nginx Server Setup - Implementing Upload/Download + Simple Upload Client
- [5] Nginx Server Setup - Folder Listing on Web
- [4] Nginx Server Setup - Writing a Drogon Test API
- [3] Nginx Server Setup - Connecting to C++ Web Framework
- [1] Nginx Server Setup - VirtualBox Installation and Putty Connection
Recommended Link
- [7] Nging Server Setup - Building a Text Detection API using Drogon Server with OpenCV
- [6] Nginx Server Setup - Implementing Upload/Download + Simple Upload Client
- [5] Nginx Server Setup - Folder Listing on Web
- [4] Nginx Server Setup - Writing a Drogon Test API
- [3] Nginx Server Setup - Connecting to C++ Web Framework
- Checking if the First Page of a PDF Contains Text and Images on RHEL
- Performance Comparison of Image Processing Frameworks: ImageMagick vs. libvips
- Checking if the First Page of a PDF Contains Text and Images on RHEL
- Performance Comparison of Image Processing Frameworks: ImageMagick vs. libvips
Instead of installing Nginx directly to the system path, this guide explains how to download, build, and set up Nginx manually. --- ## Setup Environment - Red Hat Enterprise Linux release 9.4 (Plow) ## 1. Download and Extract Nginx To download and extract Nginx: ``` wget http://nginx.org/download/nginx-1.21.6.tar.gz tar -xvf nginx-1.21.6.tar.gz ``` To download a different version, simply change the version number in the command and proceed with the steps as outlined. --- ## 2. Install Required Libraries Install essential libraries: ``` sudo yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel ``` ``` Explanation of each library: - gcc: The C compiler required to compile Nginx source code into an executable. - pcre: Provides regular expression handling for Nginx. - pcre-devel: Contains development headers needed when compiling Nginx. - zlib: Enables gzip compression in Nginx. - zlib-devel: Provides zlibs development files needed for compiling. - openssl: Necessary for SSL/TLS encryption, enabling HTTPS. - openssl-devel: Includes OpenSSLs development headers, required to compile Nginx with SSL/TLS support. ``` --- ### If you encounter the following error during installation: ``` Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs) 0.0 B/s | 0 B 00:00 Errors during downloading metadata for repository 'rhel-9-for-x86_64-baseos-rpms': - Curl error (91): SSL server certificate status verification FAILED for https://cdn.redhat.com/content/dist/rhel9/9/x86_64/baseos/os/repodata/repomd.xml [OCSP response has expired] Error: Failed to download metadata for repo 'rhel-9-for-x86_64-baseos-rpms': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried" ``` This issue is due to a time discrepancy. To resolve it, run: ``` systemctl restart chronyd ``` --- ## 3. Set Up Paths Install to the "/root" directory with the following commands: ``` ./configure --prefix=$PWD/build --sbin-path=/root/nginx/sbin/nginx --conf-path=/root/nginx/conf/nginx.conf --error-log-path=/root/nginx/logs/error.log --http-log-path=/root/nginx/logs/access.log --http-client-body-temp-path=/root/nginx/client_body_temp --http-proxy-temp-path=/root/nginx/proxy_temp --http-fastcgi-temp-path=/root/nginx/fastcgi_temp --pid-path=/root/nginx/logs/nginx.pid --lock-path=/root/nginx/logs/nginx.lock make make install ``` ### 3-1. Explanation of Each Configuration Option ``` 1. ./configure --prefix=$PWD/build": Sets the installation directory to a "build" folder in the current directory. 2. --sbin-path=/root/nginx/sbin/nginx": Specifies the path for the "nginx" executable. 3. --conf-path=/root/nginx/conf/nginx.conf": Sets the path for the Nginx configuration file. 4. --error-log-path=/root/nginx/logs/error.log": Sets the error log file path. 5. --http-log-path=/root/nginx/logs/access.log": Specifies the path for the HTTP request log. 6. --http-client-body-temp-path=/root/nginx/client_body_temp": Defines the path for temporary files of client body content. 7. --http-proxy-temp-path=/root/nginx/proxy_temp": Sets the proxy request temporary file storage path. 8. --http-fastcgi-temp-path=/root/nginx/fastcgi_temp": Specifies the FastCGI request temporary file path. 9. --pid-path=/root/nginx/logs/nginx.pid": Sets the process ID file path. 10. --lock-path=/root/nginx/logs/nginx.lock": Defines the lock file path to prevent duplicate runs. ``` --- ## 4. Confirm Installation To confirm the installation: ``` [root@vbox nginx]# pwd /root/nginx [root@vbox nginx]# ll total 4 drwxr-xr-x. 2 root root 4096 Nov 3 23:47 conf drwxr-xr-x. 2 root root 6 Nov 3 23:47 logs drwxr-xr-x. 2 root root 19 Nov 3 23:47 sbin ``` --- ## 5. Configure Nginx Server Set up the configuration as follows: ``` worker_processes 1024; events { worker_connections 1024; use epoll; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; large_client_header_buffers 4 16k; server { listen 10099; server_name localhost; location / { root html; index index.html index.htm; } } } ``` --- ## 6. Run Nginx Navigate to the sbin directory where Nginx is installed and start it: ``` cd /root/nginx/sbin ./nginx ``` To check if it’s running, use: s -ef | grep nginx Example output: ``` nobody 44425 43920 0 23:56 ? 00:00:00 nginx: worker process nobody 44426 43920 0 23:56 ? 00:00:00 nginx: worker process nobody 44427 43920 0 23:56 ? 00:00:00 nginx: worker process nobody 44428 43920 0 23:56 ? 00:00:00 nginx: worker process nobody 44429 43920 0 23:56 ? 00:00:00 nginx: worker process ``` --- ## 7. Confirm Accessibility As this server runs on a VM, you need to configure port forwarding and disable the firewall for access. ### 7-1. Add Port Forwarding Example configuration: ### 7-2. Disable the Firewall ``` [root@vbox nginx] $ sudo firewall-cmd --permanent --add-port=10099/tcp success [root@vbox nginx] $ sudo firewall-cmd --reload success ``` --- ## 8. Verify Functionality Confirm functionality in the browser. --- ## Accessing Nginx Logs Example log entries: ``` 10.0.2.2 - - [04/Nov/2024:00:06:21 +0900] "GET / HTTP/1.1" 403 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" 10.0.2.2 - - [04/Nov/2024:00:06:22 +0900] "GET /favicon.ico HTTP/1.1" 500 579 "http://127.0.0.1:10099/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" ``` --- ---Related Links
---Recommended Link
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
댓글
댓글 쓰기