How to install and build Nginx server on Linux

PHPz
Release: 2023-05-11 22:52:04
forward
1876 people have browsed it

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++
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

8. Compile the source code and install nginx:

make

make install
Copy after login

9. Start nginx:

cd /usr/local/nginx/sbin/
./nginx -c /usr/local/nginx/conf/nginx.cof
Copy after login

Visit in the browser: http://localhost

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

ps aux|grep nginx
Copy after login

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
Copy after login

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

cd /usr/local/nginx/sbin
./nginx -s quit
Copy after login

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!

Related labels:
source:yisu.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template