1024programmer Nginx How to compile and install Nginx

How to compile and install Nginx

Nginx can be compiled and run on most Unix like OS, and there is a ported version for Windows. at present
The 1.0.0 stable version of Nginx has been released. The development version is 0.9.x, the stable version is 0.8.x, and the historical stable version is 0.7.x. It is recommended to use
0.8 series as production releases. On June 1, 2011, nginx 1.0.4 was released.

advantage:

In the case of high concurrent connections, Nginx is a good substitute for the Apache server: Nginx is one of the software platforms often chosen by the bosses of the virtual hosting business in the United States. capable of supporting up to
The response of 50,000 concurrent connections, thanks to Nginx for choosing epoll and kqueue as the development model for us.

Nginx as a load balancing server: Nginx can directly support Rails and PHP programs to serve externally internally, and can also be used as
The HTTP proxy server provides external services. Nginx is written in C, and it is much better than Perlbal in terms of system resource overhead and CPU usage efficiency.

As a mail proxy server: Nginx
It is also a very good mail proxy server (one of the earliest purposes of developing this product is also as a mail proxy server), Last.fm
Describes a successful and wonderful experience with it.

Nginx is a server with very simple installation, very concise configuration files (it can also support perl syntax), and very few bugs: Nginx
It is very easy to start, and it can run almost 7*24, even if it runs for several months, it does not need to be restarted. You can also upgrade the software version without interruption of service.

1. Compile and install nginx (official document http://wiki.nginx.org/Main)

1. Module dependencies:

The gzip module requires the zlib library

The rewrite module requires the pcre library

The ssl functionality requires the openssl library

#yum install gcc openssl-devel pcre-devel
zlib-devel (gcc compilation environment)

2. nginx compilation

First add nginx users and user groups

# groupadd nginx

# useradd -g nginx -s /bin/false -M
nginx

  Unzip the source package, the latest source package 1.0.4 is used here

#tar -zxf nginx-1.0.4.tar.gz

#cd nginx-1.0.4

#./configure\

–prefix=/usr \

–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_flv_module \

–with-http_stub_status_module\

–with-http_gzip_static_module \

–http-client-body-temp-path=/var/tmp/nginx/client/
\

–http-proxy-temp-path=/var/tmp/nginx/proxy/ \

–http-fastcgi-temp-path=/var/tmp/nginx/fcgi/

#make && make install

#makedir -p
/var/log/nginx (the log directory will not be created during compilation, it needs to be created manually)

  Create a startup script /etc/init.d/nginx (can also be downloaded from the official documentation

http://wiki.nginx.org/RedHatNginxInitScript)

You can also create your own

#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: – 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/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/sbin/nginx”
prog=$(basename $nginx)
NGINX_CONF_FILE=”/etc/nginx/nginx.conf”
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/ngin

#In the case where the access_log directive is not specified in nginx.conf, the default access log path. If not specified, defaults to
PATH/logs/access.log.

–http-log-path=PATH

#In the case that no user directive is specified in nginx.conf, the default user used by nginx. If not specified, defaults to nobody.

–user=USER

#In the case that no user directive is specified in nginx.conf, the default group used by nginx. If not specified, the default

Think nobody.

–group=GROUP

#Specify the compiled directory

–builddir=DIR

#Enable the rtsig module

–with-rtsig_module

#Allow or not to enable SELECT mode, if configure does not find a suitable mode, for example, kqueue(sun os), epoll(linux
kenel 2.6+), rtsig (real-time signal)

–with-select_module (–without-select_module)

#Allow or not to enable POLL mode, if not suitable, enable this mode.

–with-poll_module (–without-poll_module)

#Enable the HTTP SSL module so that NGINX can support HTTPS requests. This module needs to have installed OPENSSL, in

libssl-dev on DEBIAN

–with-http_ssl_module

–with-http_realip_module #Enable ngx_http_realip_module

–with-http_addition_module #Enable ngx_http_addition_module

–with-http_sub_module #Enable ngx_http_sub_module

–with-http_dav_module #Enable ngx_http_dav_module

–with-http_flv_module #Enable ngx_http_flv_module

–with-http_stub_status_module #Enable “server status” page

–without-http_charset_module #Disable ngx_http_charset_module

–without-http_gzip_module #Disable ngx_http_gzip_module. If enabled, required
zlib.

–without-http_ssi_module #Disable ngx_http_ssi_module

–without-http_userid_module #Disable ngx_http_userid_module

–without-http_access_module #Disable ngx_http_access_module

–without-http_auth_basic_module #Disable
ngx_http_auth_basic_module

–without-http_autoindex_module #disable
ngx_http_autoindex_module

–without-http_geo_module #Disable ngx_http_geo_module

–without-http_map_module #Disable ngx_http_map_module

–without-http_referer_module #Disable ngx_http_referer_module

–without-http_rewrite_module # Disable ngx_http_rewrite_module.
PCRE is required if enabled.

–without-http_proxy_module #Disable ngx_http_proxy_module

–without-http_fastcgi_module #Disable ngx_http_fastcgi_module

–without-http_memcached_module #Disable
ngx_http_memcached_module

–without-http_limit_zone_module #Disable
ngx_http_limit_zone_module

–without-http_empty_gif_module #Disable
ngx_http_empty_gif_module

–without-http_browser_module #Disable ngx_http_browser_module

–without-http_upstream_ip_hash_module
#Disable ngx_http_upstream_ip_hash_module

–with-http_perl_module – # Enable ngx_http_perl_module

–with-perl_modules_path=PATH #Specify the path of the perl module

–with-perl=PATH #Specify the path of the perl execution file

–http-log-path=PATH #Set path to the http access log

–http-client-body-temp-path=PATH #Set path to the http client
request body

temporary files

–http-proxy-temp-path=PATH #Set path to the http proxy
temporary files

–http-fastcgi-temp-path=PATH #Set path to the http fastcgi
temporary files

–without-http #Disable HTTP server

–with-mail #Enable IMAP4/POP3/SMTP proxy module

–with-mail_ssl_module #Enable ngx_mail_ssl_module

–with-cc=PATH #Specify the path of the C compiler

–with-cpp=PATH #Specify the path of the C preprocessor

–with-cc-opt=OPTIONS #

–with-ld-opt=OPTIONS #Additional parameters passed to the
linker. With the use

of the system library PCRE in FreeBSD, it is necessary to
indicate –with-ld-opt=”-L /usr/local/lib”.

–with-cpu-opt=CPU #Compile for a specific CPU, valid values ​​include: pentium,
pentiumpro,

pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64,
ppc64

–without-pcre #Disable the use of the PCRE library. It also disables the HTTP rewrite module. exist

Regular expressions in the “location” configuration directive also require PCRE .

–with-pcre=DIR #Specify the path of the source code of the PCRE library.

–with-pcre-opt=OPTIONS #Set additional compilation options for PCRE.

–with-md5=DIR #Use MD5 to assemble the source code.

–with-md5-opt=OPTIONS #Set additional options for md5
building.

–with-md5-asm #Use md5 assembler sources.

–with-sha1=DIR #Set path to sha1 library sources.

–with-sha1-opt=OPTIONS #Set additional options for sha1
building.

–with-sha1-asm #Use sha1 assembler sources.

–with-zlib=DIR #Set path to zlib library sources.

–with-zlib-opt=OPTIONS #Set additional options for zlib
building.

–with-zlib-asm=CPU #Use zlib assembler sources optimized for
specified CPU, valid values ​​are: pentium, pentiumpro

–with-openssl=DIR #Set path to OpenSSL library sources

–with-openssl-opt=OPTIONS #Set additional options for OpenSSL
building

–with-debug #Enable debug logging

–add-module=PATH #Add in a third-party module found in
directory PATH

Options may change slightly between releases, always use ./configure –help to check the current list of options.

onal options for zlib
building.

–with-zlib-asm=CPU #Use zlib assembler sources optimized for
specified CPU, valid values ​​are: pentium, pentiumpro

–with-openssl=DIR #Set path to OpenSSL library sources

–with-openssl-opt=OPTIONS #Set additional options for OpenSSL
building

–with-debug #Enable debug logging

–add-module=PATH #Add in a third-party module found in
directory PATH

Options may change slightly between releases, always use ./configure –help to check the current list of options.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/how-to-compile-and-install-nginx/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索