1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Nginx实战基础篇一 源码包编译安装部署web服务器

Nginx实战基础篇一 源码包编译安装部署web服务器

时间:2019-03-16 05:32:20

相关推荐

Nginx实战基础篇一 源码包编译安装部署web服务器

Nginx实战基础篇一源码包编译安装部署web服务器

版权声明:

本文遵循“署名非商业性使用相同方式共享 2.5 中国大陆”协议

您可以自由复制、发行、展览、表演、放映、广播或通过信息网络传播本作品

您可以根据本作品演义自己的作品

您必须按照作者或者许可人指定的方式对作品进行署名。

您不得将本作品用于商业目的。

如果您改变、转换本作品或者以本作品为基础进行创作,您只能采用与本协议相同的许可协议发布基于本作品的演绎作品。

对任何再使用或者发行,您都必须向他人清楚地展示本作品使用的许可协议条款。

如果得到著作权人的许可,您可以不受任何这些条件的限制。

Designed by 小诺(dreamfire.

实验步骤:

一、安装nginx必须的依赖包

[root@rhel6u3-7~]#yum-yinstallgccopenssl-develpcre-develzlib-devel//yum创建过程略,安装略

二、安装编译nginx,目前系统测试环境为rhel6.3软件版本为nginx-1.27

[root@rhel6u3-7~]#useraddnginx-s/sbin/nologin//给nginx服务器创建后台进程管理用户[root@rhel6u3-7~]#tarzxvfnginx-1.2.7.tar.gz//解压缩[root@rhel6u3-7~]#cdnginx-1.2.7[root@rhel6u3-7nginx-1.2.7]#./configure--user=nginx--group=nginx--prefix=/usr/local/nginx/--with-http_stub_status_module--with-http_ssl_module//--user=nginx–group=nginx设置允许nginx允许的用户和组为nginx//--prefix=/usr/local/nginx/设置nginx安装路径//--with-http_stub_status_module安装允许状态模块//--with-http_ssl_module安装ssl模块//更多参数请参看./configure--help……//安装显示略,如果配置正确,最后会显示以下信息。Configurationsummary+usingsystemPCRElibrary+usingsystemOpenSSLlibrary+md5:usingOpenSSLlibrary+sha1:usingOpenSSLlibrary+usingsystemzliblibrarynginxpathprefix:"/usr/local/nginx/"nginxbinaryfile:"/usr/local/nginx//sbin/nginx"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"[root@rhel6u3-7~]#/usr/local/nginx/sbin/nginx–V//安装完成后查看Nginx的相关环境配置信息是否正确nginxversion:nginx/1.2.7builtbygcc4.4.60305(RedHat4.4.6-4)(GCC)TLSSNIsupportenabledconfigurearguments:--user=nginx--group=nginx--prefix=/usr/local/nginx/--with-http_stub_status_module--with-http_ssl_module[root@rhel6u3-7~]#[root@rhel6u3-7nginx-1.2.7]#make&makeinstall//编译安装过程略

三、通过nginx自身脚本机器nginx服务器,并通过各种命令查看是否启动成功

[root@rhel6u3-7~]#/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf//-c指向nginx主配置文件[root@rhel6u3-7~]#lsof-i:80//查看nginx进程号及运行情况COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAMEnginx4080root6uIPv4214670t0TCP*:http(LISTEN)nginx4081nginx6uIPv4214670t0TCP*:http(LISTEN)[root@rhel6u3-7~]#ps-ef|grepnginx//查看nginx进程号及运行情况root40801022:24?00:00:00nginx:masterprocess/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.confnginx40814080022:24?00:00:00nginx:workerprocessroot40881433022:27pts/000:00:00grepnginx[root@rhel6u3-7~]#netstat-nltp|grep80//查看nginx进程监听端口tcp000.0.0.0:800.0.0.0:*LISTEN4080/nginx

四,测试nginx配置的默认web服务器是否能正常运行

通过linux自带命令links 测试

[root@rhel6u3-7~]#links127.0.0.1//出现welcometonginx!说明nginx服务启动成功

通过windows服务器IE浏览器测试

扩展知识:

1、设置nginx开机自动启动,将nginx启动命令添加到/etc/rc.local

[root@rhel6u3-7~]#echo"/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf">>/etc/rc.local[root@rhel6u3-7~]#cat/etc/rc.local|grepnginx/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf

2、通过设置System V 脚本,使用server命令启动nginx服务

[root@rhel6u3-7init.d]#vimnginx//在/etc/init.d/下创建nginx启动脚本文件#!/bin/sh##nginx-thisscriptstartsandstopsthenginxdaemon##chkconfig:-8515#description:NginxisanHTTP(S)server,HTTP(S)reverse\#proxyandIMAP/POP3proxyserver#processname:nginx#config:/etc/nginx/nginx.conf#config:/etc/sysconfig/nginx#pidfile:/var/run/nginx.pid#Sourcefunctionlibrary../etc/rc.d/init.d/functions#Sourcenetworkingconfiguration../etc/sysconfig/network#Checkthatnetworkingisup.["$NETWORKING"="no"]&&exit0nginx="/usr/local/nginx/sbin/nginx"prog=$(basename$nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"[-f/etc/sysconfig/nginx]&&./etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxstart(){[-x$nginx]||exit5[-f$NGINX_CONF_FILE]||exit6echo-n$"Starting$prog:"daemon$nginx-c$NGINX_CONF_FILEretval=$?echo[$retval-eq0]&&touch$lockfilereturn$retval}stop(){echo-n$"Stopping$prog:"killproc$prog-QUITretval=$?echo[$retval-eq0]&&rm-f$lockfilereturn$retvalkillall-9nginx}restart(){configtest||return$?stopsleep1start}reload(){configtest||return$?echo-n$"Reloading$prog:"killproc$nginx-HUPRETVAL=$?echo}force_reload(){restart}configtest(){$nginx-t-c$NGINX_CONF_FILE}rh_status(){status$prog}rh_status_q(){rh_status>/dev/null2>&1}case"$1"instart)rh_status_q&&exit0$1;;stop)rh_status_q||exit0$1;;restart|configtest)$1;;reload)rh_status_q||exit7$1;;force-reload)force_reload;;status)rh_status;;condrestart|try-restart)rh_status_q||exit0;;*)echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"exit2esac

[root@rhel6u3-7init.d]#chmod755nginx//修改脚本文件nginx的权限[root@rhel6u3-7init.d]#chkconfig--addnginx//将脚本文件加入chkconfig中[root@rhel6u3-7init.d]#chkconfig--level35nginxon//设置nginx开机在3和5级别自动启动[root@rhel6u3-7init.d]#chkconfig--list|grepnginxnginx0:off1:off2:off3:on4:off5:on6:off

Nginx实战基础篇PDF高清下载系列:

Nginx实战基础篇一:源码包编译安装部署web服务器

/data/688744

Nginx实战基础篇二:Nginx主配置文件参数详解

/data/688835

Nginx实战基础篇三:Nginx上虚拟主机的实现过程

/data/688836

Nginx实战基础篇四:通过https方式安全访问web服务器

/data/689197

Nginx实战基础篇五:Nginx上实现用户名密码认证访问

/data/694934

Nginx实战基础篇六:通过源码包编译安装部署LNMP搭建Discuz论坛

/data/694932

测试nginx脚本文件是否能够正常使用

[root@rhel6u3-7init.d]#/etc/init.d/nginxrestart//重新启动nginx:theconfigurationfile/usr/local/nginx/conf/nginx.confsyntaxisoknginx:configurationfile/usr/local/nginx/conf/nginx.conftestissuccessfulStoppingnginx:[OK]Startingnginx:[OK][root@rhel6u3-7init.d]#/etc/init.d/nginxreload//不间断服务平滑重启nginx:theconfigurationfile/usr/local/nginx/conf/nginx.confsyntaxisoknginx:configurationfile/usr/local/nginx/conf/nginx.conftestissuccessfulReloadingnginx:[OK][root@rhel6u3-7~]#cat/usr/local/nginx/logs/nginx.pid//存储了nginx运行的进程号15799[root@rhel6u3-7~]#kill-HUP`cat/usr/local/nginx/logs/nginx.pid`//不间断服务重新启动nginx[root@rhel6u3-7init.d]#/etc/init.d/nginxstopStoppingnginx:[OK][root@rhel6u3-7init.d]#killall-9nginx//结束nginx的全部经常

[root@rhel6u3-7html]#pwd//安装nginx完成后,默认网站的路径/usr/local/nginx/html[root@rhel6u3-7html]#ll//可以查看到默认网站为index.html,内容为以上测试内容。total8-rw-r--r--1rootroot537Feb2522:2150x.html-rw-r--r--1rootroot612Feb2522:21index.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。