天天看點

linux安裝LNMP環境之安裝nginx

安裝nginx
確定沒有安裝擴充
yum install wget gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel
           

然後:

cd /usr/local/src/
           
wget http://nginx.org/download/nginx-1.12.2.tar.gz
           

下載下傳完成之後解壓:

tar zxvf nginx-1.12.2.tar.gz
           

預編譯:

[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre --with-http_gzip_static_module --with-http_dav_module   --with-http_addition_module  --with-http_sub_module --with-http_flv_module  --with-http_mp4_module
           

解釋:

--with-http_gzip_static_module :支援壓縮

--with-http_stub_status_module :支援nginx狀态查詢

--with-http_ssl_module :支援https

--with-pcre :為了支援rewrite重寫功能,必須制定pcre

--with-http_dav_module #啟用支援(增加PUT,DELETE,MKCOL:建立集合,COPY和MOVE方法)

--with-http_addition_module #啟用支援(作為一個輸出過濾器,支援不完全緩沖,分部分相應請求)

--with-http_sub_module #啟用支援(允許一些其他文本替換Nginx相應中的一些文本)

--with-http_flv_module #啟用支援(提供支援flv視訊檔案支援)

--with-http_mp4_module #啟用支援(提供支援mp4視訊檔案支援,提供僞流媒體服務端支援)

編譯:

make && make install 
           

添加系統變量(友善啟停服務)

vim /etc/profile
           

第56行添加

export PATH=/usr/local/nginx/sbin:$PATH
           

然後重新啟動

source /etc/profile
           

添加軟連接配接

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
           

伺服器啟動腳本:

vim /etc/init.d/nginx
           

把下面内容放進去

#!/bin/bash
# chkconfig: - 99 2
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
        start)
        $PROG
        ;;
        stop)
        kill -3 $(cat $PIDF)
        ;;
        restart)
        $0 stop &> /dev/null
        if [ $? -ne 0 ] ; then continue ; fi
        $0 start
        ;;
        reload)
        kill -1 $(cat $PIDF)
        ;;
        *)
        echo "Userage: $0 { start | stop | restart | reload }"
        exit 1
esac
exit 0

           

配置服務開機自動啟動

[root@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig nginx on
           

配置完了可以用一下指令控制nginx狀态:

service nginx restart
service nginx start
service nginx stop
           

打開浏覽器輸入你的ip就可以看到welcome to nginx!