安裝說明
yum方式安裝Nginx,並配置開機啓動
在新機器上首次安裝nginx以前,須要設置nginx軟件包存儲庫。以後,能夠從存儲庫安裝和更新nginx。html
yum install yum-utils
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
yum-config-manager --enable nginx-mainline
yum install nginx
安裝完成
啓動Nginx:nginx
nginx -v 查看Nginx版本 whereis nginx 查看Nginx默認目錄 nginx 啓動Nginx nginx -t 測試命令 nginx -s relaod 修改nginx.conf以後,能夠重載
Nginx的默認路徑:web
Nginx配置路徑:/etc/nginx/ PID目錄:/var/run/nginx.pid 錯誤日誌:/var/log/nginx/error.log 訪問日誌:/var/log/nginx/access.log 默認站點目錄:/usr/share/nginx/html 默認啓動文件: /usr/sbin/nginx
進入到/etc/init.d/目錄下,配置nginx啓動文件:vim
vim /etc/init.d/nginx #!/bin/bash #nginx Startup script for the Nginx HTTP Server #it is v.0.0.2 version. #chkconfig: - 85 15 #description: Nginx is a high-performance web and proxy server. #It has a lot of features, but it's not for everyone. #processname: nginx #pidfile: /var/run/nginx.pid #config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/sbin/nginx # nginx真實啓動文件路徑 nginx_config=/etc/nginx/conf.d/default.conf #nginx配置文件路徑 nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" #Source function library. . /etc/rc.d/init.d/functions #Source networking configuration. . /etc/sysconfig/network #Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 #Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } #Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } #reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } #See how we were called. 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}" exit 1 esac exit $RETVAL
chmod 755 nginx 啓動測試: systemctl restart nginx systemctl enable nginx 查看進程: