Home >Backend Development >PHP Tutorial >Compile and install nginx on CentOS 71

Compile and install nginx on CentOS 71

WBOY
WBOYOriginal
2016-07-29 08:59:38862browse

The article is reproduced from: https://typecodes.com/web/centos7compilenginx.html
If there is a compilation error, check: https://typecodes.com/web/solvenginxcompileerror.html
1 Dependency library configuration, compile and install Nginx1.9.0
Create first A user named nginx without login permissions and a user group named nginx, then install the dependent libraries and dependent packages required by nginx, and finally configure the installation details through .configure. In addition, add a pcre tar package backup address: https://dn-vfhky.qbox.me/libs/nginx/pcre-8.36.tar.gz, and a zlib tar package backup address: https://dn -vfhky.qbox.me/libs/nginx/zlib-1.2.8.tar.gz.
#######Create new nginx user and nginx group
[root@typecodes ~]# groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx
####### yum installs the necessary dependencies for nginx
[root@typecodes ~]# yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed
#######Official website download Nginx1.9.0 tar package, and then extract it to the server
[root@typecodes ~]# wget -c http://nginx.org/download/nginx-1.9.0.tar.gz
[root@typecodes ~]# tar -zxf nginx-1.9.0.tar.gz && cd nginx-1.9.0
#######Download the tar package of pcre and decompress it to support the Rewrite function of Nginx
[root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/php/pcre-8.36.tar.gz && tar -zxf pcre-8.36.tar.gz
#######Download the zlib tar package and unzip it , in order to support Nginx’s Gzip compression function
[root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/nginx/zlib-1.2.8.tar.gz
[root@ typecodes nginx-1.9.0]# tar -zxf zlib-1.2.8.tar.gz
#######Create the directory required for Nginx1.9.0 installation
[root@typecodes nginx-1.9.0]# cd /var/tmp/ && mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
[root@typecodes tmp]# mkdir -p /var/run/nginx && cd ~/nginx -1.9.0
After the preparations are completed, start the formal configuration of the installation details of Nginx-1.9.0.Note that when using the configure parameter configuration below, you must first remove the comment text added after the backslash ""! ! !
[root@typecodes nginx-1.9.0]# ./configure
--prefix=/usr/share/nginx [Nginx installation directory]
--sbin-path=/usr/sbin/nginx [Nginx sbin directory] P ----conf-path =/etc/nginx/nginx.conf [configuration file of nginx]
-error-log-path =/var/log/nginx/error.log [nginx's error log]
HTTP -log-path=/var/log/nginx/access.log [Nginx access log]
--pid-path=/var/run/nginx/nginx.pid [Nginx process ID]
--lock-path =/var/lock/nginx.lock
--user=nginx                                                                                                                                                            ​                    [Nginx’s ssl module]
--with-http_spdy_module [Google spdy module for Nginx]
--with-http_dav_module
--with-http_flv_module
--with-http_realip_module
--with-http_addition_module
--with-http_xslt_module
--with-http_stub_status_module
--with-http_sub_module ule
--With-http_random_index_module
--all-http_degradation_module
------http_secure_link_module
Compression Module] w-With-HTTP_PERL_MODULE
-With-PCRE = PCRE-8.36 [PCRE Installation Directory]
--with-zlib=zlib-1.2.8 [pcre installation directory]
--with-debug [Allow DEBUG]
--with-file-aio
--with-mail
--with-mail _ssl_module
--http-client-body-temp-path=/var/tmp/nginx/client_body
--http-proxy-temp-path=/var/tmp/nginx/proxy
--http-fastcgi-temp-path =/var/tmp/nginx/fastcgi
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
--http-scgi-temp-path=/var/tmp/nginx/scgi
-- With-Stream [nginx1.9.0-unique Stream module]
--all-ld -opt = "-wl, -e" [Compilation and Optimization of GCC]
You may encounter problems: ./configure: error: perl module ExtUtils::Embed is required
Problem description: This module is missing, you need to install the following with yum
Solution: yum install perl perl-devel perl-ExtUtils-Embed
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/ log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/ lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_spdy_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module --with-http_perl_module --with-pcre=pcre-8.36 --with-zlib=zlib-1.2.8 --with-debug --with-file -aio --with-mail --with-mail_ssl_module --http-client-body-temp-path=/var/tmp/nginx/client_body --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp /nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-stream --with-ld-opt="-Wl,-E"
The configuration process takes about 5 minutes
2 After configuration, you can compile and install directly. Finally, just execute this command [root@typecodes nginx-1.9.0]# make && make install to install.
[root@typecodes nginx-1.9.0]# make && make install
3 Configure Nginx1.9.0 to make it work properly
After successfully installing Nginx1.9.0, we need to perform some configurations, including booting, SSL/HTTPS service, etc. . Among them, the Nginx service control script nginx can be found in the article "SHELL script for starting, stopping and restarting Nginx service".
https://typecodes.com/web/nginxserviceoptshell.html
#######Upload the Nginx service control script nginx, and grant execution permissions, delete the installation package, and add the Nginx service to startup
This step may appear If you don’t have an nginx service script, download one yourself, or copy the one below, and then name the file nginx
#file starts
#!/bin/bash
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig : - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx .conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig /network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_C /usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2> ;&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
#End of file
[root@typecodes ~]# mv ~/nginx /etc/init.d/nginx && chmod +x /etc/init.d/nginx
If /etc/init.d/nginx exists, do not overwrite it, just execute chmod +x /etc/init.d/nginx
[ root@typecodes ~]# rm -rf nginx-1.9.0*
[root@typecodes ~]# chkconfig --add nginx
[root@typecodes ~]# chkconfig nginx on
#######Test whether the configuration is OK
root@typecodes ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
##### ##Create a new Nginx process log nginx.pid directory and start the service
Add this mkdir to be compatible with server restart
[root@typecodes ~]# mkdir -p /var/run/nginx/
[root@ typecodes ~]# service nginx start
The above introduces the compilation and installation of nginx on CentOS 71, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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