Home  >  Article  >  Operation and Maintenance  >  How to compile and install nginx in lnmp environment

How to compile and install nginx in lnmp environment

WBOY
WBOYforward
2023-05-23 12:34:061034browse

The Linux system I use is centos7.1.

If the Linux system does not have pre-installed gcc and other compilation software, you can use the yum source to install it. To install nginx, you first need to install the dependent modules pcre, zlib, and openssl.

gzip module requires zlib library

rewrite module requires pcre library

ssl function requires openssl library

1. Install pcre dependencies

  • Download pcre-8.38 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar .gz

  • Extract tar -zxvf pcre-8.38.tar.gz

  • Enter the decompression directory cd your directory/pcre-8.38

  • Compile./configure --prefix=/opt/project/pcre #Specify the installation directory

  • Install after the compilation is complete make && make install

2. Install zlib dependencies

  • Download zlib-1.2.11 wget

  • Extract tar -zxvf zlib-1.2.11.tar.gz

  • Enter the decompression directory cd your directory/zlib-1.2.11

  • Compile./configure --prefix=/opt/project/zlib #Specify the installation directory

  • After compilation is completed, install make && make install

3. Install openssl dependencies

  • Download openssl-1.1.1-pre5 wget

  • Extract tar -zxvf openssl-1.1.1-pre5.tar.gz

  • Enter the decompression directory cd your directory/openssl-1.1.1-pre5

  • Compile./configure --prefix=/opt/project/openssl #Specify the installation directory

  • After compilation is completed, install make && make install

4. Install nginx service

Manually create nginx user and user group

groupadd nginx

useradd nginx -g nginx -s /sbin/nologin -m

  • Download wget

  • Unzip tar -zxvf nginx-1.14. 0.tar.gz

  • Compile

./configure --prefix=/opt/project/nginx-1.14 #nginx Installation location
--sbin-path=/opt/project/nginx-1.14/sbin/nginx #Set nginx executable file path
--conf-path=/opt/project/nginx-1.14/config/ nginx.conf #Set nginx configuration file path
--pid-path=/opt/project/nginx-1.14/logs/nginx.pid #Set nginx.pid file
--error-log-path=/ opt/project/nginx-1.14/logs/error.log #Set the name of the main error, warning, and diagnostic files
--lock-path=/opt/project/nginx-1.14/logs/nginx.log \
--http-log-path=/opt/project/nginx-1.14/logs/access.log #Set the name of the log file of the http server for the main request
--with-http_ssl_module
--user =nginx \
--group=nginx \
--with-pcre=/var/software/nginx/pcre-8.38 #Refers to the source code path of pcre
--with-zlib=/var /software/nginx/zlib-1.2.11 #Referring to the source code path of zlib
--with-openssl=/var/software/nginx/openssl-1.1.1-pre5 #Referring to the source code path of openssl

  • Install make && make install

  • After nginx is compiled and installed, modify nginx.conf

user nginx nginx;

Start nginx /opt/project/nginx/nginx

Restart nginx /opt/project/nginx/nginx -s reload

Kill the process pkill -9 nignx

View the port netstat -ano|grep 80

View the process ps -ef|grep nginx
6>

How to compile and install nginx in lnmp environment

If you cannot access, you need to turn off the firewall.

centos7 Check the firewall status
firewall-cmd --state #running The firewall is running (not running is closed)

Close the firewall
systemctl stop firewalld.service #Stop firewall
systemctl disable firewalld.service #Disable firewall startup

If you encounter problems during the installation process, please google it yourself, because the errors encountered may be different depending on the system.

The above is the detailed content of How to compile and install nginx in lnmp environment. 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