CentOS 7下编译安装Nginx 1.11.10教程
前言
之前分享过一篇CentOS下编译安装nginx及配置缩略图插件的方法教程,当时的环境是CentOS6.x和Nginx1.9.x。本次安装的环境为CentOS7.2和Nginx1.11.10,有些配置以前自启动的方式发生了变化,这里再记录一下。
安装编译安装依赖的类库和包
yuminstallgccgcc-c++autoconfautomakezlibzlib-developensslopenssl-develpcre-devel
下载和解压Nginx1.11.10
wgethttp://nginx.org/download/nginx-1.11.10.tar.gz tar-xzvfnginx-1.11.10.tar.gz cdnginx-1.11.10
配置Nginx安装选项
这里编译了插件http_image_filter_module,来实现图片的处理,采用默认的安装路径进行安装。
./configure\ --with-http_ssl_module\ --with-http_v2_module\ --with-http_realip_module\ --with-http_addition_module\ --with-http_xslt_module\ --with-http_image_filter_module\ --with-http_sub_module\ --with-http_auth_request_module\ --with-http_stub_status_module\ --with-http_gzip_static_module
运行结果如下
[root@xxnginx-1.11.10]#./configure\ >--with-http_ssl_module\ >--with-http_v2_module\ >--with-http_realip_module\ >--with-http_addition_module\ >--with-http_xslt_module\ >--with-http_image_filter_module\ >--with-http_sub_module\ >--with-http_auth_request_module\ >--with-http_stub_status_module\ >--with-http_gzip_static_module checkingforOS +Linux3.10.0-327.22.2.el7.x86_64x86_64 checkingforCcompiler...found +usingGNUCcompiler +gccversion:4.8.520150623(RedHat4.8.5-11)(GCC) checkingforgcc-pipeswitch...found checkingfor-Wl,-Eswitch...found checkingforgccbuiltinatomicoperations...found checkingforC99variadicmacros...found checkingforgccvariadicmacros...found checkingforgccbuiltin64bitbyteswap...found checkingforunistd.h...found checkingforinttypes.h...found checkingforlimits.h...found checkingforsys/filio.h...notfound checkingforsys/param.h...found checkingforsys/mount.h...found checkingforsys/statvfs.h...found checkingforcrypt.h...found checkingforLinuxspecificfeatures checkingforepoll...found checkingforEPOLLRDHUP...found checkingforEPOLLEXCLUSIVE...notfound checkingforO_PATH...found checkingforsendfile()...found checkingforsendfile64()...found checkingforsys/prctl.h...found checkingforprctl(PR_SET_DUMPABLE)...found checkingforsched_setaffinity()...found checkingforcrypt_r()...found checkingforsys/vfs.h...found checkingforpoll()...found checkingfor/dev/poll...notfound checkingforkqueue...notfound checkingforcrypt()...notfound checkingforcrypt()inlibcrypt...found checkingforF_READAHEAD...notfound checkingforposix_fadvise()...found checkingforO_DIRECT...found checkingforF_NOCACHE...notfound checkingfordirectio()...notfound checkingforstatfs()...found checkingforstatvfs()...found checkingfordlopen()...notfound checkingfordlopen()inlibdl...found checkingforsched_yield()...found checkingforSO_SETFIB...notfound checkingforSO_REUSEPORT...found checkingforSO_ACCEPTFILTER...notfound checkingforSO_BINDANY...notfound checkingforIP_BIND_ADDRESS_NO_PORT...notfound checkingforIP_TRANSPARENT...found checkingforIP_BINDANY...notfound checkingforIP_RECVDSTADDR...notfound checkingforIP_PKTINFO...found checkingforIPV6_RECVPKTINFO...found checkingforTCP_DEFER_ACCEPT...found checkingforTCP_KEEPIDLE...found checkingforTCP_FASTOPEN...found checkingforTCP_INFO...found checkingforaccept4()...found checkingforeventfd()...found checkingforintsize...4bytes checkingforlongsize...8bytes checkingforlonglongsize...8bytes checkingforvoid*size...8bytes checkingforuint32_t...found checkingforuint64_t...found checkingforsig_atomic_t...found checkingforsig_atomic_tsize...4bytes checkingforsocklen_t...found checkingforin_addr_t...found checkingforin_port_t...found checkingforrlim_t...found checkingforuintptr_t...uintptr_tfound checkingforsystembyteordering...littleendian checkingforsize_tsize...8bytes checkingforoff_tsize...8bytes checkingfortime_tsize...8bytes checkingforAF_INET6...found checkingforsetproctitle()...notfound checkingforpread()...found checkingforpwrite()...found checkingforpwritev()...found checkingforsys_nerr...found checkingforlocaltime_r()...found checkingforposix_memalign()...found checkingformemalign()...found checkingformmap(MAP_ANON|MAP_SHARED)...found checkingformmap("/dev/zero",MAP_SHARED)...found checkingforSystemVsharedmemory...found checkingforPOSIXsemaphores...notfound checkingforPOSIXsemaphoresinlibpthread...found checkingforstructmsghdr.msg_control...found checkingforioctl(FIONBIO)...found checkingforstructtm.tm_gmtoff...found checkingforstructdirent.d_namlen...notfound checkingforstructdirent.d_type...found checkingforsysconf(_SC_NPROCESSORS_ONLN)...found checkingforopenat(),fstatat()...found checkingforgetaddrinfo()...found checkingforPCRElibrary...found checkingforPCREJITsupport...found checkingforOpenSSLlibrary...found checkingforzliblibrary...found checkingforlibxslt...found checkingforlibexslt...found checkingforGDlibrary...found checkingforGDWebPsupport...notfound creatingobjs/Makefile Configurationsummary +usingsystemPCRElibrary +usingsystemOpenSSLlibrary +usingsystemzliblibrary nginxpathprefix:"/usr/local/nginx" nginxbinaryfile:"/usr/local/nginx/sbin/nginx" nginxmodulespath:"/usr/local/nginx/modules" nginxconfigurationprefix:"/usr/local/nginx/conf" nginxconfigurationfile:"/usr/local/nginx/conf/nginx.conf" nginxpidfile:"/usr/local/nginx/logs/nginx.pid" nginxerrorlogfile:"/usr/local/nginx/logs/error.log" nginxhttpaccesslogfile:"/usr/local/nginx/logs/access.log" nginxhttpclientrequestbodytemporaryfiles:"client_body_temp" nginxhttpproxytemporaryfiles:"proxy_temp" nginxhttpfastcgitemporaryfiles:"fastcgi_temp" nginxhttpuwsgitemporaryfiles:"uwsgi_temp" nginxhttpscgitemporaryfiles:"scgi_temp"
最后的几行是配置的结果,注意这里的pidfile那一行,后面配置服务的时候,需要用的到。
安装Nginx
使用如下命令来安装nginx。
make&&makeinstall
配置systemdNginx服务和设置Nginx自启动
centos7中采用systemd来管理系统,我们来为nginx创建服务文件,来实现通过systemd来管理nginx。
创建systemd服务文件:/lib/systemd/system/nginx.service,内容如下:
[Unit] Description=TheNGINXHTTPandreverseproxyserver After=syslog.targetnetwork.targetremote-fs.targetnss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx-t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill-sHUP$MAINPID ExecStop=/bin/kill-sQUIT$MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
这里的PIDFile的配置要和前面的配置保持一致。
设置自启动
systemctlenablenginx
通过systemd管理nginx
systemctlstartnginx systemctlstopnginx systemctlrestartnginx systemctlreloadnginx
总结
好了,打完收工。以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对毛票票的支持。