centos7系統(tǒng)下nginx安裝并配置開機自啟動操作
準(zhǔn)備工作
我的centos7系統(tǒng)是最小化安裝的, 缺很多庫, 首先安裝必須的運行庫
yum install wget gcc gcc-c++ pcre-devel zlib-devel ##創(chuàng)建工作目錄并進入工作目錄 mkdir -p /z/nginx && cd /z/nginx ##獲取nginx最新的安裝包 wget http://nginx.org/download/nginx-1.11.10.tar.gz ##解壓縮 tar zxvf nginx-1.11.10.tar.gz ##進入目錄 cd nginx-1.11.10 ##檢測系統(tǒng)配置, 生成make相關(guān)文件 ./configure
./configure執(zhí)行成功會輸出以下信息
nginx的安裝位置,以及文件路徑
Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
編譯并安裝
make && make install
創(chuàng)建nginx啟動命令腳本
vi /etc/init.d/nginx
插入以下內(nèi)容, 注意修改PATH和NAME字段, 匹配自己的安裝路徑 (這段是從網(wǎng)上copy的)
#! /bin/bash # chkconfig: - 85 15 PATH=/usr/local/nginx DESC="nginx daemon" 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" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running" } do_stop() { $DAEMON -s stop || echo -n "nginx not running" } do_reload() { $DAEMON -s reload || echo -n "nginx can't reload" } 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 $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0
設(shè)置執(zhí)行權(quán)限
chmod a+x /etc/init.d/nginx
注冊成服務(wù)
chkconfig --add nginx
設(shè)置開機啟動
chkconfig nginx on
重啟, 查看nginx服務(wù)是否自動啟動
shutdown -h 0 -r netstat -apn|grep nginx
對nginx服務(wù)執(zhí)行停止/啟動/重新讀取配置文件操作
#啟動nginx服務(wù) systemctl start nginx.service #停止nginx服務(wù) systemctl stop nginx.service #重啟nginx服務(wù) systemctl restart nginx.service #重新讀取nginx配置(這個最常用, 不用停止nginx服務(wù)就能使修改的配置生效) systemctl reload nginx.service
以上所述是小編給大家介紹的centos7系統(tǒng)下nginx安裝并配置開機自啟動操作,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
nginx 老網(wǎng)站域名重定向到新網(wǎng)站的方法(親測)
本文主要介紹了nginx 老網(wǎng)站域名重定向到新網(wǎng)站的方法,以減少業(yè)務(wù)影響并確保流量導(dǎo)向新域名,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-02-02Nginx配置PATHINFO隱藏thinkphp index.php
這篇文章主要介紹了Nginx配置PATHINFO隱藏thinkphp index.php,本文直接給出配置示例,需要的朋友可以參考下2015-07-07Nginx出現(xiàn)403 Forbidden問題的常見原因與解決
Nginx 返回 403 Forbidden 錯誤通常表示客戶端沒有權(quán)限訪問請求的資源,這種錯誤有許多可能的原因,本文將為大家介紹一下常見的原因和對應(yīng)的解決方法,希望對大家有所幫助2025-03-03Nginx proxy_set_header參數(shù)設(shè)置
本文主要介紹了Nginx proxy_set_header參數(shù)設(shè)置,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-09-09