CentOS 71 compile and install Nginx

Source: Internet
Author: User
Tags install openssl install perl nginx ssl
Article turned from: https://typecodes.com/web/centos7compilenginx.html
If compile error view: https://typecodes.com/web/solvenginxcompileerror.html
1 Relying on library configuration, compiling and installing Nginx1.9.0
Create a user named Nginx with no login permission and a user group named Nginx, then install the dependent libraries and dependent packages required by Nginx, and finalize the installation configuration with. Configure. In addition, a pcre of the 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.
###### #新建nginx用户和nginx组
[Root@typecodes ~]# groupadd-r nginx && useradd-r-G nginx-s/bin/false-m Nginx
###### #yum安装nginx必须的依赖库
[Root@typecodes ~]# yum-y install OpenSSL openssl-devel libxml2-devel libxslt-devel perl-devel perl-extutils-embed
###### #官网下载Nginx1.9.0 tar package and unzip 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
###### #下载pcre的tar包并解压 in order to support Nginx's rewrite function
[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
###### #下载zlib的tar包并解压 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
###### #新建Nginx1.9.0 directories required for 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
Once the preparation is done, the installation details of the Nginx-1.9.0 are formally configured. Note that when using the following configure parameter configuration, be sure to first remove the backslash "\" After the comment text added!!!
[Root@typecodes nginx-1.9.0]#./configure \
--prefix=/usr/share/nginx \ [nginx installation directory]
--sbin-path=/usr/sbin/nginx \ [nginx sbin directory]
--conf-path=/etc/nginx/nginx.conf \ [nginx configuration file]
--error-log-path=/var/log/nginx/error.log \ [nginx 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 user]
--group=nginx \ [Nginx belongs to user Group]
--with-http_ssl_module \ [Nginx SSL Module]
--with-http_spdy_module \ [Nginx's Google 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 \ [nginx gzip compression Module]
--with-http_perl_module \
--with-pcre=pcre-8.36 \ [installation directory of Pcre]
--with-zlib=zlib-1.2.8 \ [installation directory of Pcre]
--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-specific stream module]
--with-ld-opt= "-WL,-E" [gcc compilation optimization]
Note: The following is a well-formatted data, directly copied can
You may encounter a problem:./configure:error:perl module extutils::embed is required
Problem Description: Missing This module requires Yum to install the following
Workaround: 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 the configuration is complete, you can compile and install the
Finally, install it directly using the Execute this command [root@typecodes nginx-1.9.0]# makes && make install.
[Root@typecodes nginx-1.9.0]# make && make install
3 Configure Nginx1.9.0 to work properly
After successfully installing Nginx1.9.0, we need to do some configuration, including boot start, Ssl/https service and so on. Among them, Nginx service control script Nginx see the article "Nginx Service start, stop and restart the operation of shell script."
Https://typecodes.com/web/nginxserviceoptshell.html
###### #上传Nginx服务控制脚本nginx, and give execute permission, remove installation package, add Nginx service to boot boot
This step may appear without Nginx service script, download one yourself, or copy the following, then file name Nginx
#文件开始
#!/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 are 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 "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart|configtest)
$
;;
Reload
Rh_status_q | | Exit 7
$
;;
Force-reload)
Force_reload
;;
Status
Rh_status
;;
Condrestart|try-restart)
Rh_status_q | | Exit 0
;;
*)
echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
Exit 2
Esac
#文件结束
[Root@typecodes ~]# mv ~/nginx/etc/init.d/nginx && chmod +x/etc/init.d/nginx
If/etc/init.d/nginx exists, do not overwrite, directly 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
###### #测试配置是否正常
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
###### #新建Nginx进程日志nginx. PID directory and start the service
Plus this mkdir can be compatible with the server to restart this situation
[Root@typecodes ~]# mkdir-p/var/run/nginx/
[Root@typecodes ~]# service Nginx start

The above describes the CentOS 71 compiler installation Nginx, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.