search
HomeBackend DevelopmentPHP TutorialCompile and install nginx on CentOS 71

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
Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

What is the full form of PHP?What is the full form of PHP?Apr 28, 2025 pm 04:58 PM

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

How does PHP handle form data?How does PHP handle form data?Apr 28, 2025 pm 04:57 PM

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

What is the difference between PHP and ASP.NET?What is the difference between PHP and ASP.NET?Apr 28, 2025 pm 04:56 PM

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

Is PHP a case-sensitive language?Is PHP a case-sensitive language?Apr 28, 2025 pm 04:55 PM

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

See all articles

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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 Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool