檢查配置文件并啟動nginx服務
1.檢查配置文件 ? ? ?(推薦學習:nginx教程)
Nginx的主程序提供了“-t”選項來對配置文件進行檢查,以便找出不當或錯誤的配置。
[root@centos7-1?nginx-1.12.0]#?nginx?-t nginx:?the?configuration?file?/usr/local/nginx/conf/nginx.conf?syntax?is?ok nginx:?configuration?file?/usr/local/nginx/conf/nginx.conf?test?is?successful
2.啟動Nginx
直接運行Nginx即可啟動Nginx服務器
[root@centos7-1?nginx-1.12.0]#?nginx? [root@centos7-1?nginx-1.12.0]#?killall?-1?nginx???????//重啟nginx服務 [root@centos7-1?nginx-1.12.0]#?killall?-3?nginx??????//停止nginx服務
3.使用Nginx服務腳本
為了使nginx服務的啟動、停止、重載等操作更加方便,可以編寫nginx服務腳本,并使用chkconfig和systemctl工具來進行管理,這更加符合系統(tǒng)的管理習慣。
[root@centos7-1?nginx-1.12.0]#?vim?/etc/init.d/nginx #!/bin/bash #?chkconfig:?-?99?20 #?description:?Nginx?Service?Control?Script PROG="/usr/local/nginx/sbin/nginx"???????????????//主程序路徑 PIDF="/usr/local/nginx/logs/nginx.pid"???????????//PID存放路徑 case?"$1"?in ??start) ????$PROG ????;; ??stop) ????kill?-s?QUIT?$(cat?$PIDF)??????????????//根據(jù)PID中止nginx進程 ????;; ??restart) ????$0?stop ????$0?start ????;; ??reload) ????kill?-s?HUP?$(cat?$PIDF)??????????????//根據(jù)進程號重載配置 ????;; ??*) ????????echo?"Usage:?$0?{start|stop|restart|reload}" ????????exit?1 esac exit?0
[root@centos7-1?nginx-1.12.0]#?chmod?+x?/etc/init.d/nginx [root@centos7-1?nginx-1.12.0]#?chkconfig?--add?nginx?????????????????//添加為系統(tǒng)服務 [root@centos7-1?nginx-1.12.0]#?systemctl?start?nginx.service
確認Nginx服務是否正常運行
通過檢查Nginx程序的監(jiān)聽狀態(tài),或者在瀏覽器中訪問此Web服務,默認頁面將顯示“Welcome to nginx!”
[root@centos7-1?nginx-1.12.0]#?netstat?-antp?|?grep?nginx tcp????????0??????0?0.0.0.0:80??????????????0.0.0.0:*???????????????LISTEN??????54386/nginx:?master? [root@centos7-1?nginx-1.12.0]#?yum?install?elinks?-y [root@centos7-1?nginx-1.12.0]#?elinks?http://localhost?//使用elinks瀏覽器
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END