Home Operation and Maintenance Nginx How to install Nginx server under CentOS7

How to install Nginx server under CentOS7

May 13, 2023 pm 08:43 PM
nginx centos7

Installation required environment

nginx is developed in C language. It is recommended to run on Linux. Of course, you can also install the windows version. This article uses centos 7 as the installation environment.

1. gcc installation

To install nginx, you need to compile the source code downloaded from the official website first. The compilation depends on the gcc environment. If there is no gcc environment, you need to install it. :

yum install gcc-c++

2. pcre pcre-devel installation

pcre (perl compatible regular expressions) is a perl library, including perl compatible regular expressions library . The http module of nginx uses pcre to parse regular expressions, so the pcre library needs to be installed on Linux. pcre-devel is a secondary development library developed using pcre. nginx also requires this library. Command:

yum install -y pcre pcre-devel

3. zlib installation

The zlib library provides many compression and decompression methods. nginx uses zlib to gzip the contents of the http package. , so the zlib library needs to be installed on centos.

yum install -y zlib zlib-devel

4. openssl installation

openssl is a powerful secure socket layer cryptographic library, including major cryptographic algorithms, commonly used keys and The certificate encapsulates management functions and SSL protocols, and provides a rich set of applications for testing or other purposes.
nginx not only supports http protocol, but also supports https (that is, transmitting http over ssl protocol), so you need to install the openssl library on centos.

yum install -y openssl openssl-devel

Official website download

1. Directly download the .tar.gz installation package, address:

How to install Nginx server under CentOS7

2. Use the wget command to download ( recommend).

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

How to install Nginx server under CentOS7

I downloaded version 1.10.1, which is the current stable version.

Decompression

is still a direct command:

tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1

Configuration

In fact, it is in nginx-1.10. In version 1, you don’t need to configure related things, the default is fine. Of course, it is also possible if you want to configure the directory yourself.

1. Use the default configuration

./configure

2. Customize the configuration (not recommended)

./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

Note: Specify the temporary file directory For /var/temp/nginx, you need to create the temp and nginx directories under /var

Compile and install

make
make install

Find the installation path:

whereis nginx

How to install Nginx server under CentOS7

Start and stop nginx

cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit: The stop step in this method is to wait until the nginx process completes the task.
./nginx -s stop: This method is equivalent to first finding out the nginx process ID and then using the kill command to forcefully kill the process.

Query the nginx process:

ps aux|grep nginx

Restart nginx

1. Stop and then start (recommended):

Restarting nginx is equivalent to stopping and then starting, that is, executing the stop command first and then the start command. As follows:

./nginx -s quit
./nginx

2. Reload the configuration file:

When the ngin x configuration file nginx.conf is modified, you need to restart nginx to make the configuration take effect, use -s reload There is no need to stop ngin

Auto-start at boot

How to install Nginx server under CentOS7

Just add the startup code in rc.local.

./nginx -s reload
Add a line /usr/local/nginx/sbin/nginx

Set execution permissions:

vi /etc/rc.local


The above is the detailed content of How to install Nginx server under CentOS7. 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 Article

Peak: How To Revive Players
1 months ago By DDD
PEAK How to Emote
3 weeks ago By Jack chen

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)

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

NGINX vs. Apache: Performance, Scalability, and Efficiency NGINX vs. Apache: Performance, Scalability, and Efficiency Apr 19, 2025 am 12:05 AM

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

NGINX vs. Apache: A Comparative Analysis of Web Servers NGINX vs. Apache: A Comparative Analysis of Web Servers Apr 21, 2025 am 12:08 AM

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINX and Apache: Understanding the Key Differences NGINX and Apache: Understanding the Key Differences Apr 26, 2025 am 12:01 AM

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

How to execute php code after writing php code? Several common ways to execute php code How to execute php code after writing php code? Several common ways to execute php code May 23, 2025 pm 08:33 PM

PHP code can be executed in many ways: 1. Use the command line to directly enter the "php file name" to execute the script; 2. Put the file into the document root directory and access it through the browser through the web server; 3. Run it in the IDE and use the built-in debugging tool; 4. Use the online PHP sandbox or code execution platform for testing.

After installing Nginx, the configuration file path and initial settings After installing Nginx, the configuration file path and initial settings May 16, 2025 pm 10:54 PM

Understanding Nginx's configuration file path and initial settings is very important because it is the first step in optimizing and managing a web server. 1) The configuration file path is usually /etc/nginx/nginx.conf. The syntax can be found and tested using the nginx-t command. 2) The initial settings include global settings (such as user, worker_processes) and HTTP settings (such as include, log_format). These settings allow customization and extension according to requirements. Incorrect configuration may lead to performance issues and security vulnerabilities.

See all articles