Home >Operation and Maintenance >Nginx >How to install and build Nginx server on Linux

How to install and build Nginx server on Linux

PHPz
PHPzforward
2023-05-11 22:52:041914browse

1. Upload the nginx compressed package nginx-1.8.0.tar.gz to the linux server

2. Since nginx is developed in C language and we install nginx here by compiling the source code of nginx , so you need to install the c language compilation environment gcc on Linux.
If you have already installed this step, you can omit it. Otherwise, execute the command:

yum install gcc-c++

3. The http module of nginx uses pcre to parse regular expressions, so The pcre library needs to be installed on linux.

yum install -y pcre pcre-devel

4. 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 Linux.

yum install -y zlib zlib-devel

5.nginx not only supports the http protocol, but also supports https (that is, transmitting http over the ssl protocol), so you need to install the openssl library on Linux.

yum install -y openssl openssl-devel

6. Create a temporary directory for nginx on Linux. Note that I created the folder temp under /var in the Linux file system and created nginx under temp. That is:/var/temp/nginx

7. Execute the command:

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/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

8. Compile the source code and install nginx:

make

make install

9. Start nginx:

cd /usr/local/nginx/sbin/
./nginx -c /usr/local/nginx/conf/nginx.cof

Visit in the browser: http://localhost

We can also check the running status of the nginx process at this time:

ps aux|grep nginx

10. How to stop the nginx server:

Method 1: First find out the nginx process ID and then use the kill command to forcefully kill the process.

cd /usr/local/nginx/sbin
./nginx -s stop

Method 2 (recommended): Stop the nginx process after it completes the task.

cd /usr/local/nginx/sbin
./nginx -s quit

The above is the detailed content of How to install and build Nginx server on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete