centos7系统下nginx安装并配置开机自启动操作
准备工作
我的centos7系统是最小化安装的,缺很多库,首先安装必须的运行库
yuminstallwgetgccgcc-c++pcre-develzlib-devel ##创建工作目录并进入工作目录 mkdir-p/z/nginx&&cd/z/nginx ##获取nginx最新的安装包 wgethttp://nginx.org/download/nginx-1.11.10.tar.gz ##解压缩 tarzxvfnginx-1.11.10.tar.gz ##进入目录 cdnginx-1.11.10 ##检测系统配置,生成make相关文件 ./configure
./configure执行成功会输出以下信息
nginx的安装位置,以及文件路径
Configurationsummary +usingsystemPCRElibrary +OpenSSLlibraryisnotused +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"
编译并安装
make&&makeinstall
创建nginx启动命令脚本
vi/etc/init.d/nginx
插入以下内容,注意修改PATH和NAME字段,匹配自己的安装路径(这段是从网上copy的)
#!/bin/bash #chkconfig:-8515 PATH=/usr/local/nginx DESC="nginxdaemon" NAME=nginx DAEMON=$PATH/sbin/$NAME CONFIGFILE=$PATH/conf/$NAME.conf PIDFILE=$PATH/logs/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set-e [-x"$DAEMON"]||exit0 do_start(){ $DAEMON-c$CONFIGFILE||echo-n"nginxalreadyrunning" } do_stop(){ $DAEMON-sstop||echo-n"nginxnotrunning" } do_reload(){ $DAEMON-sreload||echo-n"nginxcan'treload" } case"$1"in start) echo-n"Starting$DESC:$NAME" do_start echo"." ;; stop) echo-n"Stopping$DESC:$NAME" do_stop echo"." ;; reload|graceful) echo-n"Reloading$DESCconfiguration..." do_reload echo"." ;; restart) echo-n"Restarting$DESC:$NAME" do_stop do_start echo"." ;; *) echo"Usage:$SCRIPTNAME{start|stop|reload|restart}">&2 exit3 ;; esac exit0
设置执行权限
chmoda+x/etc/init.d/nginx
注册成服务
chkconfig--addnginx
设置开机启动
chkconfignginxon
重启,查看nginx服务是否自动启动
shutdown-h0-r netstat-apn|grepnginx
对nginx服务执行停止/启动/重新读取配置文件操作
#启动nginx服务 systemctlstartnginx.service #停止nginx服务 systemctlstopnginx.service #重启nginx服务 systemctlrestartnginx.service #重新读取nginx配置(这个最常用,不用停止nginx服务就能使修改的配置生效) systemctlreloadnginx.service
以上所述是小编给大家介绍的centos7系统下nginx安装并配置开机自启动操作,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!