CentOS 7中Nginx1.9.5編譯安裝教程systemctl啟動
阿新 • • 發佈:2017-08-22
pat align temp prefix 軟件 復制代碼 all automake 軟件目錄
先安裝gcc 等
- yum -y install gcc gcc-c++ wget
- yum -y install gcc wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
進入默認的軟件目錄
- cd /usr/local/src/
下載 nginx軟件
- wget http://nginx.org/download/nginx-1.9.5.tar.gz
如果這個下載太慢可以在這裏下載http://nginx.org/download/nginx-1.9.5.tar.gz 下載完後yum -y intall lrzsz 裝好上傳工具
然後用rz上傳到服務器
然後解壓文件.
- tar zxvf nginx-1.9.5.tar.gz
進入 nginx1.9.5的源碼 如果想改版本號 可以進入源碼目錄src/core/nginx.h更改
- cd nginx-1.9.5/
創建一個nginx目錄用來存放運行的臨時文件夾
- mkdir -p /var/cache/nginx
開始configure
- ./configure \
- --prefix=/usr/local/nginx \
- --sbin-path=/usr/sbin/nginx \
- --conf-path=/etc/nginx/nginx.conf \
- --error-log-path=/var/log/nginx/error.log \
- --http-log-path=/var/log/nginx/access.log \
- --pid-path=/var/run/nginx.pid \
- --lock-path=/var/run/nginx.lock \
- --http-client-body-temp-path=/var/cache/nginx/client_temp \
- --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
- --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
- --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
- --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
- --user=nobody \
- --group=nobody \
- --with-pcre \
- --with-http_v2_module \
- --with-http_ssl_module \
- --with-http_realip_module \
- --with-http_addition_module \
- --with-http_sub_module \
- --with-http_dav_module \
- --with-http_flv_module \
- --with-http_mp4_module \
- --with-http_gunzip_module \
- --with-http_gzip_static_module \
- --with-http_random_index_module \
- --with-http_secure_link_module \
- --with-http_stub_status_module \
- --with-http_auth_request_module \
- --with-mail \
- --with-mail_ssl_module \
- --with-file-aio \
- --with-ipv6 \
- --with-http_v2_module \
- --with-threads \
- --with-stream \
- --with-stream_ssl_module
接著 編譯
- make
安裝
- make install
啟動nginx
- /usr/sbin/nginx
用ps aux來查看nginx是否啟動
- ps aux|grep nginx
然後配置服務
- vim /usr/lib/systemd/system/nginx.service
按i輸入以下內容
- [Unit]
- Description=nginx - high performance web server
- Documentation=http://nginx.org/en/docs/
- After=network.target remote-fs.target nss-lookup.target
- [Service]
- Type=forking
- PIDFile=/var/run/nginx.pid
- ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
- ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
- ExecReload=/bin/kill -s HUP $MAINPID
- ExecStop=/bin/kill -s QUIT $MAINPID
- PrivateTmp=true
- [Install]
- WantedBy=multi-user.target
編輯好後保存
然後開啟開機啟動
- systemctl enable nginx.service
用命令關掉nginx
- pkill -9 nginx
後面可以用systemctl來操作nginx.service
- systemctl start nginx.service
然後php裝好後更改配置 編輯/etc/nginx/nginx.conf
CentOS 7中Nginx1.9.5編譯安裝教程systemctl啟動