CentOS 7.2 A detailed tutorial on installing Nginx 1.10.2 _linux

Source: Internet
Author: User
Tags install openssl md5 openssl openssl lib sha1

First, the use of Yum installation (recommended)

Using Yum installation is the recommended way, the overall process is very simple, not easy to make mistakes, if you do not need any special configuration, it is recommended to use Yum to install.

1, install the epel-release source and install

Yum install epel-release
yum update
yum install Nginx

2, the implementation of relevant application operations

Systemctl start Nginx #启动
systemctl stop nginx #停止
systemctl restart Nginx #重启
systemctl status Nginx #查看运行状态
Systemctl Enable Nginx #开机启动

3, set the firewall

You may not be able to access IP after startup, you need to further set up your firewall

Firewall-cmd--permanent--zone=public--add-service=http firewall-cmd--permanent--zone=public--add-service= 
HTTPS
Firewall-cmd--reload

At this point, the installation is complete.

Reference article: Https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

Second, compile the installation through the source code

1, install the necessary tools for compiling

Yum Groupinstall "Development Tools"
yum install wget

2, to the official website download the latest source code (https://nginx.org/en/)

CD/USR/LOCAL/SRC
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.2.tar.gz

3, install the dependent package

Yum install zlib zlib-devel OpenSSL openssl-devel pcre pcre-devel

Zlib: Provide gzip module for Nginx, need zlib library support, transfer data package, save traffic (but consume resources)

OpenSSL: Provides SSL functionality for Nginx

Pcre: Rewriting rewrite features for support addresses

4. Create users and groups to run Nginx

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

The-G parameter specifies a group for the Nginx user. The-m parameter guarantees that it does not automatically generate a home directory.

5. Compile source code

First Use ./configure –help view compilation help:

[Root@localhost nginx-1.10.2]#./configure--help--help Print this message--prefix=path set Installat
 Ion prefix #Nginx安装的根路径, default to/usr/local/nginx.
 --sbin-path=path set Nginx binary pathname #指定nginx二进制文件的路径, the default is Path/sbin/nginx. --modules-path=path set Modules path #Perl模块位置--conf-path=path set nginx.conf pathname #设定nginx配置文件地址, default to Path/con
 F/nginx.conf.
 --error-log-path=path Set error log pathname #错误文件路径, default to Path/logs/error.log.
 --pid-path=path set Nginx.pid Pathname # Master Process PID writes to the file location, usually under Var/run, and the default is Path/logs/nginx.pid. --lock-path=path set Nginx.lock pathname #共享存储器互斥锁文件路径--user=user set non-privileged user for worker Processe S #指定程序运行时的非特权用户--group=group set non-privileged group for worker processes #指定程序运行时的非特权用户组--build=name SE T build name #编译名称--builddir=dir Set build directory #指向编译目录--with-select_module enable select module Allow or disallow Open Select Mode if configure does not find a suitable pattern, for example, Kqueue (Sun OS), Epoll (LinUX Kenel 2.6+), Rtsig (real-time signal)--without-select_module Disable Select module Disable select modules Support--with-poll_module enable PO LL module enables poll module support (same functionality as SELECT, same as Select feature, for a polling mode, not recommended for high load environments)--without-poll_module Disable Poll module disables poll module branch Hold--with-threads enable thread pool support--with-file-aio enable file AIO support #为freeBSD4.3+ and linux2.6. 22+ system enables asynchronous IO--with-ipv6 enable IPV6 support #启用ipv6支持 #默认禁用的模块--with-http_ssl_module enable Ngx_http_ssl_mo Dule #使支持https请求, install OpenSSL--with-http_v2_module enable Ngx_http_v2_module #启用HTTP V2--with-http_realip_module E Nable Ngx_http_realip_module #此模块支持显示真实来源IP地址, mainly used for Nginx to do front-end load balancing server using--with-http_addition_module enable NGX_HTTP_ Addition_module #输出过滤器 enables you to add content to the location itself before or after a request is location--with-http_xslt_module enable Ngx_http_xslt_module #这个模块是一个过滤器, it can transform XML answers through the XSLT template--with-http_xslt_module=dynamic enable dynamic Ngx_http_xslt_module--with-http_ Image_filter_module Enable Ngx_http_image_filTer_module #图像过滤器 to process the image before it is posted to the customer (requires a LIBGD library)--with-http_image_filter_module=dynamic enable dynamic Ngx_http_ima Ge_filter_module--with-http_geoip_module enable Ngx_http_geoip_module #创建基于与MaxMind geoip matching client address--with-http_geoip _module=dynamic Enable dynamic Ngx_http_geoip_module--with-http_sub_module enable Ngx_http_sub_module #这个模块可以能够在ngin X answer to search for and replace text--with-http_dav_module enable Ngx_http_dav_module #为文件和目录指定权限, restrict different types of users to have different permissions on the page--with-http_flv_ The drag playback of the module enable Ngx_http_flv_module #这个模块支持对FLV (Flash) file--with-http_mp4_module enable Ngx_http_mp4_module #支持H. The 264/aac file is a pseudo streaming media--with-http_gunzip_module enable Ngx_http_gunzip_module #对于不支持gzip编码的客户, which is used to extract the uncompressed content for the customer--with-http _gzip_static_module enable Ngx_http_gzip_static_module a compressed file that ends with ". Gz" #这个模块在一个预压缩文件传送到开启Gzip压缩的客户端之前检查是否已经存在以. This prevents the file from being repeatedly compressed--with-http_auth_request_module enable Ngx_http_auth_request_module--with-http_random_index_module Enable Ngx_http_random_index_module #从目录中选择一个随机主页-The-with-http_secure_link_module enable Ngx_http_secure_link_module #该模块提供一种机制, which links a hash value to a URL, so Only those who use the correct password can compute the link--with-http_degradation_module enable Ngx_http_degradation_module #允许在内存不足的情况下返回204或444码-- With-http_slice_module enable Ngx_http_slice_module--with-http_stub_status_module enable Ngx_http_stub_status_ Module #取得一些nginx的运行状态, the state information of the output can be plotted using RRDtool or similar tools #默认启用的模块--without-http_charset_module disable ngx_http_charset_ Module #重新编码web页面--without-http_gzip_module Disable Ngx_http_gzip_module #同-with-http_gzip_static_module function-- Without-http_ssi_module Disable Ngx_http_ssi_module #提供在输入端处理处理服务器包含文件 (SSI) filter, the list currently supporting SSI commands is incomplete--WITHOUT-HTTP_ Userid_module Disable Ngx_http_userid_module #用来处理用来确定客户端后续请求的cookies--without-http_access_module disable NGX_HTTP_ Access_module #供了一个简单的基于主机的访问控制. Allow/deny based on IP address--without-http_auth_basic_module disable Ngx_http_auth_basic_module # You can use the user name and password based on the HTTP Basic authentication method to protect your site or some of its content--without-http_autoindex_module disable Ngx_http_autoinDex_module #自动生成目录列表, the request is made only if the Ngx_http_index_module module does not find the index file. --without-http_geo_module disable Ngx_http_geo_module #创建一些变量, whose value is dependent on the IP address of the client--without-http_map_module disable NGX_HT Tp_map_module #使用任意的键/value pair settings configuration variable--without-http_split_clients_module disable Ngx_http_split_clients_module # Used to divide users based on certain conditions. Conditions such as: IP address, header, cookies, etc.--without-http_referer_module disable Ngx_http_referer_module #用来过滤请求, reject the Referer value in the header is not correct request-- The without-http_rewrite_module disable Ngx_http_rewrite_module is #允许使用正则表达式改变URI and is shifted according to variables and selected for configuration--without-http_proxy_ module Disable ngx_http_proxy_module #有关代理服务器--without-http_fastcgi_module disable Ngx_http_fastcgi_module #允许Nginx and
 FastCGI process interaction and control FastCGI process work by passing parameters.   --without-http_uwsgi_module Disable Ngx_http_uwsgi_module #用来使用uwsgi协议, Uwsgi server-related--without-http_scgi_module
 Disable Ngx_http_scgi_module #用来启用SCGI协议支持, the SCGI protocol is an alternative to the CGI protocol. --without-http_memcached_module disable Ngx_http_memcached_module #用来提供简单的缓存 to improve system efficiency--without-http_limit_conn_ module Disable NGX_HTTp_limit_conn_module #允许你对于一个地址进行连接数的限制用一个给定的session或一个特定的事件--without-http_limit_req_module Disable NGX_HTTP_ Limit_req_module #允许你对于一个地址进行请求数量的限制用一个给定的session或一个特定的事件--without-http_empty_gif_module Disable Ngx_http_empty_ Gif_module #在内存中常驻了一个1 *1 Transparent GIF image, can be very fast call--without-http_browser_module disable Ngx_http_browser_module # Used to create a value that relies on the request header--without-http_upstream_hash_module disable Ngx_http_upstream_hash_module #用于简单的负载均衡--without-h 
          Ttp_upstream_ip_hash_module Disable Ngx_http_upstream_ip_hash_module--without-http_upstream_least_conn_module Disable Ngx_http_upstream_least_conn_module--without-http_upstream_keepalive_module disable NGX_HT Tp_upstream_keepalive_module--without-http_upstream_zone_module Disable Ngx_http_upstream_zone_module--wit H-http_perl_module Enable Ngx_http_perl_module #这个模块允许nginx使用SSI调用perl或直接执行perl (use degrades performance)--with-http_perl_module= Dynamic Enable dynamic Ngx_http_perl_module--with-perl_modulEs_path=path Set Perl modules path #设定perl模块路径--with-perl=path set perl binary pathname #设定perl库文件路径--http-log-  Path=path Set HTTP access log Pathname #设定access log path--http-client-body-temp-path=path set path to store HTTP client Request body Temporary Files #设定http客户端请求临时文件路径--http-proxy-temp-path=path the set path to store HTTP proxy temporary file s #设定http代理临时文件路径--http-fastcgi-temp-path=path set path to store HTTP fastcgi temporary files #设定http fastcgi temporary file path--   Http-uwsgi-temp-path=path set path to store HTTP uwsgi temporary files #设定http uwsgi temporary file path--http-scgi-temp-path=path Set path to store HTTP scgi temporary files #设定http scgi temporary file path--without-http Disable HTTP server #完全禁用http模块 If you only want to Support for Mall, you can use this setting--without-http-cache disable HTTP cache #在使用upstream模块时, Nginx can configure local cache content, this option disables caching--with-mail E Nable POP3/IMAP4/SMTP Proxy module #激活POP3/IMAP4/SMTP proxy modules, default inactive--with-mail=dynamic enable Dynamic POP3/IMAP4/SMTP Pro XY module--with-mail_sSl_module enable Ngx_mail_ssl_module #SMTP可以使用SSL/tls. Configuration has already defined HTTP SSL modules, but does not support client certificate detection--without-mail_pop3_module DISA ble ngx_mail_pop3_module #启用mail模块后, disable POP3 module--without-mail_imap_module disable Ngx_mail_imap_module #启用mail模块后 separately, Disable the IMAP module--without-mail_smtp_module disable ngx_mail_smtp_module alone #启用mail模块后, disable the SMTP module individually--with-stream enable T CP/UDP Proxy module--with-stream=dynamic enable dynamic TCP/UDP proxy module--with-stream_ssl_module enable ngx_s Tream_ssl_module--without-stream_limit_conn_module Disable Ngx_stream_limit_conn_module--without-stream_access_ Module Disable Ngx_stream_access_module--without-stream_upstream_hash_module disable Ngx_stream_upstream_hash _module--without-stream_upstream_least_conn_module Disable Ngx_stream_upstream_least_conn_module--without-st Ream_upstream_zone_module Disable Ngx_stream_upstream_zone_module--with-google_perftools_module enable Ngx_ Google_perftools_module #调试用, profiling procedure performance bottleCervical--with-cpp_test_module Enable Ngx_cpp_test_module--add-module=path enable external module #启用外部模块支持--add-d Ynamic-module=path enable dynamic external module #编译相关的参数--with-cc=path set C compiler pathname #如果想设置一个不在默认path Under the C compiler--with-cpp=path set C preprocessor Pathname #设置c预处理器的相对路径--with-cc-opt=options set additional C compiler  Options #设置C编译器参数--with-ld-opt=options Set additional linker options #包含连接库的路径和运行路径--WITH-CPU-OPT=CPU build for The specified CPU, valid values:pentium, Pentiumpro, pentium3, Pentium4,athlon, Opteron, Sparc32, SPARC64, PPC64 #指定编译的CP U--without-pcre disable Pcre library usage #禁用pcre库--with-pcre Force pcre Library Usage #启用pcre库--with-p  Cre=dir set path to PCRE library sources #指向pcre库文件目录--with-pcre-opt=options set additional builds OPTIONS for PCRE #在编译时为pcre库设置附加参数--with-pcre-jit build Pcre with JIT compilation support--with-md5=dir set path to MD5 Lib Rary sources #指向md5库文件目录
 --with-md5-opt=options set additional build OPTIONS to MD5 #在编译时为md5库设置附加参数--WITH-MD5-ASM use MD5 assembler s Ources #使用md5汇编源--with-sha1=dir set path to SHA1 library sources #指向sha1库目录--with-sha1-opt=options set Additio      NAL build options for SHA1 #在编译时为sha1库设置附加参数--with-sha1-asm use SHA1 assembler sources #使用sha1汇编源--with-zlib=dir Set path to zlib library sources #指向zlib库目录--with-zlib-opt=options set additional builds OPTIONS for zlib #在编译时为zl IB set additional parameters--with-zlib-asm=cpu use zlib assembler sources optimized for the specified CPU, valid values:pentium, Pentiu Mpro #为指定的CPU使用zlib汇编源进行优化--with-libatomic Force libatomic_ops Library Usage # provides a framework for the implementation of update operations for atomic memory--with-libatom Ic=dir set path to Libatomic_ops library sources #指向libatomic_ops安装目录--with-openssl=dir set path to OpenSSL Lib
 
 Rary sources #指向openssl安装目录--with-openssl-opt=options set additional build OPTIONS for OpenSSL #在编译时为openssl设置附加参数 --with-debug Enable Debug Logging #启用debug日志 

To set compilation parameters:

./configure \
--prefix=/usr/local/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.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-pcre \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_ Gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_ Secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module

Then, make && make install after completing the installation, add scripts for Nginx startup, restart, and overload configuration in CENTOS7:

Vi/usr/lib/systemd/system/nginx

Add Content:

[Unit]
Description=nginx-high Performance Web server
documentation=http://nginx.org/en/docs/
after= Network.target remote-fs.target nss-lookup.target
 
[Service]
type=forking
pidfile=/var/run/nginx.pid
execstartpre=/usr/sbin/nginx-t-c/etc/nginx/nginx.conf
Execstart=/usr/sbin/nginx-c/etc/nginx/nginx.conf
execreload=/bin/kill-s HUP $MAINPID
execstop=/bin/ Kill-s QUIT $MAINPID
privatetmp=true
 
[Install]
Wantedby=multi-user.target

Related actions:

Systemctl is-enabled nginx.service #查询nginx是否开机启动
systemctl enable Nginx.service #开机运行nginx
systemctl Disable Nginx.service #取消开机运行nginx
systemctl start nginx.service #启动nginx
systemctl stop Nginx.service #停止nginx
Systemctl Restart Nginx.service #重启nginx
systemctl reload nginx.service #重新加载nginx配置文件
systemctl Status Nginx.service #查询nginx运行状态
systemctl--failed #显示启动失败的服务

Summarize

The above is CentOS 7.2 installation Nginx 1.10.2 Detailed tutorials, I hope this article on the content of everyone's study or work can bring some help, if you have questions you can message exchange.

Related Article

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.