centos 7 編譯安裝Nginx

#創建用戶組www,創建用戶www 所屬組 www 設置不能登錄

groupadd www && useradd -g www www -s /bin/false

#安裝nginx編譯所需依賴包
#http_image_filter_module模塊需要gd庫
#這裏是安裝二進制包,也可以下載源碼包編譯安裝

yum -y install zlib zlib-devel openssl* pcre pcre-devel gd-devel

#進入下載源碼包目錄

#下載源碼包

#解壓源碼包

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

#進入解壓好的源碼包準備編譯安裝

cd nginx-1.15.5

#編譯nginx

./configure \
--prefix=/data/server/nginx/ \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_realip_module \
--with-http_image_filter_module

#如果沒有報錯 則進行編譯安裝

make && make install

#安裝成功後,進入安裝目錄
#備份原配置

#修改nginx.conf

整合Nginx+PHP
加到server標籤裏

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

location ~ \.php$ {

                    root 【根目錄文件路徑,默認是html,即 nginx 路徑下的/html】;
                    # fastcgi_pass 端口默認爲 9000 fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php; #默認值
                    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
                    #調整值 給出文件的真實路徑  
                    fastcgi_param SCRIPT_FILENAME 【根目錄文件路徑】/$fastcgi_script_name;
                    include fastcgi_params;
                    }

創建啓動腳本,並啓動nginx

cp /data/server/nginx/sbin/nginx /data/service/nginx


/data/service/nginx -t
/data/service/nginx 

#測試phpinfo

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章