Linux 6下安装编译安装Nginx的步骤
Linux6下安装编译安装Nginx的步骤
前言:
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。在高连接并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达50,000个并发连接数的响应,而且内存开销极小。这也是Nginx广受欢迎的重要原因。本文演示了基于Linux6下编译安装Nginx,供大家参考。
一、安装环境
#cat/etc/issue RedHatEnterpriseLinuxServerrelease6.3(Santiago) Kernel\ronan\m #nginx-v nginxversion:nginx/1.8.0
二、配置安装环境
###为简化安装及配置,此处关闭了防火墙,生产环境建议开启 #serviceiptablesstop #chkconfigiptablesoff #vi/etc/selinux/config SELINUX=disabled ###创建用户及组 #groupadd-rnginx #useradd-s/sbin/nologin-gnginx-rnginx ###安装环境依赖包http://nginx.org/en/linux_packages.html #yuminstallpcre-develzlib-developensslopenssl-develgccgcc-c++
三、编译及安装Nginx
#cd/tmp/ #tar-xvfnginx-1.8.0.tar.gz #cd/nginx-1.8.0 #./configure\ --prefix=/etc/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\ --http-client-body-temp-path=/var/cache/nginx/client_temp\ --http-proxy-temp-path=/var/cache/nginx/proxy_temp\ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp\ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp\ --http-scgi-temp-path=/var/cache/nginx/scgi_temp\ --user=nginx\ --group=nginx\ --with-http_ssl_module\ --with-http_realip_module\ --with-http_addition_module\ --with-http_sub_module\ --with-http_dav_module\ --with-http_flv_module\ --with-http_mp4_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\ --with-mail\ --with-mail_ssl_module\ --with-file-aio\ --with-http_spdy_module\ --with-ipv6 Configurationsummary +usingsystemPCRElibrary +usingsystemOpenSSLlibrary +md5:usingOpenSSLlibrary +sha1:usingOpenSSLlibrary +usingsystemzliblibrary nginxpathprefix:"/etc/nginx" nginxbinaryfile:"/usr/sbin/nginx" nginxconfigurationprefix:"/etc/nginx" nginxconfigurationfile:"/etc/nginx/nginx.conf" nginxpidfile:"/var/run/nginx.pid" nginxerrorlogfile:"/var/log/nginx/error.log" nginxhttpaccesslogfile:"/var/log/nginx/access.log" nginxhttpclientrequestbodytemporaryfiles:"/var/cache/nginx/client_temp" nginxhttpproxytemporaryfiles:"/var/cache/nginx/proxy_temp" nginxhttpfastcgitemporaryfiles:"/var/cache/nginx/fastcgi_temp" nginxhttpuwsgitemporaryfiles:"/var/cache/nginx/uwsgi_temp" nginxhttpscgitemporaryfiles:"/var/cache/nginx/scgi_temp" ###如果apachehttpd服务启动,建议先停止或更改端口号 #servicehttpdstop #mkdir-p/var/cache/nginx/{client_temp,proxy_temp,fastcgi_temp,uwsgi_temp,scgi_temp} #make&&makeinstall ###启动nginx #/usr/sbin/nginx-c/etc/nginx/nginx.conf #ps-ef|grepnginx|grep-vgrep root334121010:18?00:00:00nginx:masterprocess/usr/sbin/nginx-c/etc/nginx/nginx.conf nginx3341333412010:18?00:00:00nginx:workerprocess [root@orasrv1cache]#netstat-nltp|grep80 tcp000.0.0.0:800.0.0.0:*LISTEN33412/nginx [root@orasrv1cache]#
四、配置nginx为系统服务
vi/etc/init.d/nginx #!/bin/bash #nginxStartupscriptfortheNginxHTTPServer #chkconfig:-8515 #description:NginxisanHTTP(S)server,HTTP(S)reverse\ #proxyandIMAP/POP3proxyserver #Author:Leshami #Blog:http://blog.csdn.net/leshami #processname:nginx #pidfile:/var/run/nginx.pid #config:/etc/nginx/nginx.conf #pathfornginxbinary nginxd=/usr/sbin/nginx #pathfornginxconfiguration nginx_config=/etc/nginx/nginx.conf #pathfornginxpid nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" #Sourcefunctionlibrary. ./etc/rc.d/init.d/functions #Sourcenetworkingconfiguration. ./etc/sysconfig/network #Checkthatnetworkingisup. [${NETWORKING}="no"]&&exit0 [-x$nginxd]||exit0 #Startnginxdaemonsfunctions. start(){ if[-e$nginx_pid];then echo"nginxalreadyrunning...." exit1 fi echo-n$"Starting$prog:" daemon$nginxd-c${nginx_config} RETVAL=$? echo [$RETVAL=0]&&touch/var/lock/subsys/nginx return$RETVAL } #Stopnginxdaemonsfunctions. stop(){ echo-n$"Stopping$prog:" killproc$nginxd RETVAL=$? echo [$RETVAL=0]&&rm-f/var/lock/subsys/nginx/var/run/nginx.pid } #reloadnginxservicefunctions. reload(){ echo-n$"Reloading$prog:" #kill-HUP`cat${nginx_pid}` killproc$nginxd-HUP RETVAL=$? echo } #Seehowwewerecalled. case"$1"in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status$prog RETVAL=$? ;; *) echo$"Usage:$prog{start|stop|restart|reload|status|help}" exit1 esac exit$RETVAL #chmodu+x/etc/init.d/nginx #servicenginxstart Startingnginx:[OK] #ps-ef|grepnginx|grep-vgrep root335341010:33?00:00:00nginx:masterprocess/usr/sbin/nginx-c/etc/nginx/nginx.conf nginx3353533534010:33?00:00:00nginx:workerprocess #servicenginxstop Stoppingnginx:[OK] #chkconfig--addnginx #chkconfignginxon
五、安装过程中的常见故障
./configure:error:theHTTPrewritemodulerequiresthePCRElibrary. Youcaneitherdisablethemodulebyusing--without-http_rewrite_module option,orinstallthePCRElibraryintothesystem,orbuildthePCRElibrary staticallyfromthesourcewithnginxbyusing--with-pcre=option. ./configure:error:theHTTPgzipmodulerequiresthezliblibrary. Youcaneitherdisablethemodulebyusing--without-http_gzip_module option,orinstallthezliblibraryintothesystem,orbuildthezliblibrary staticallyfromthesourcewithnginxbyusing--with-zlib= option. ###以上2个错误,请安装相应的依赖包,见本文第二部分:配置安装环境 #/usr/sbin/nginx nginx:[emerg]getpwnam("nginx")failed ###需要创建nginx用户组及用户 #/usr/sbin/nginx nginx:[emerg]mkdir()"/var/cache/nginx/client_temp"failed(2:Nosuchfileordirectory) ###需要创建对应的目录
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!