系統版本:CentOS 6.9 x86_64
軟件版本:nginx-1.12.2
php-5.5.38
可道雲kodexplorer4.37php
1.1 建立目錄html
mkdir -p /service/tools mkdir /application cd /service/tools wget http://nginx.org/download/nginx-1.12.2.tar.gz 下載或者上傳nginx包
1.2 解壓python
tar zxvf nginx-1.12.2.tar.gz
1.3 編譯安裝linux
yum install gcc gcc-c++ glibc -y #安裝編譯器 yum install pcre-devel zlib-devel openssl-devel –y
裝pcre爲了重寫rewrite提供正則表達式庫,裝zlib爲了gzip提供數據壓縮用的函數庫,裝openssl爲 Nginx 模塊(如 ssl )提供密碼算法、證書以及 SSL 協議等功能
C語言源碼包,須要編譯才能使用
編譯安裝三部曲nginx
./configure(指定編譯參數:安裝目錄及版本) cd nginx-1.12.2 ./configure --prefix=/application/nginx-1.12.2 --pid-path=/var/run/nginx.pid --user=nginx --group=nginx --with-http_ssl_module ./configure -help #查看幫助
生成Makefile文件
make
make是用來編譯的,它從Makefile中讀取指令,而後編譯c++
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules \ -o objs/src/http/modules/ngx_http_geo_module.o \ src/http/modules/ngx_http_geo_module.c
make install
make install是用來安裝的,它也從Makefile中讀取指令,安裝到指定的位置正則表達式
[root@Web01 nginx-1.12.2]# cd /application/nginx-1.12.2/ [root@Web01 nginx1.12.2]# ls -1 conf #配置文件 html #網站html文件 logs #日誌 sbin #二進制的執行文件
1.4 配置算法
建立軟連接shell
ln -s /application/nginx-1.12.2 /application/nginx ln -s /application/nginx/sbin/nginx /usr/bin/ useradd -M -s /sbin/nologin -r -u 88 nginx #建立用戶 -M 不建立用戶的HOME目錄 -s shell 指定默認登陸shell -r 建立系統帳戶 -u uid 爲帳戶指定一個惟一的UID conf目錄 fastcgi.conf 配合php uwsgi_params 配合python nginx.conf 主配置文件 mime.types 多媒體資源類型配置文件
最小化配置文件vim
grep -Ev '^$|#' nginx.conf.default >nginx.conf [root@Web01 conf]# grep -Ev '^$|#' nginx.conf.default >nginx.conf [root@Web01 conf]# cat nginx.conf worker_processes 1; #工做進程數 events { #event模塊 worker_connections 1024; #默認工做鏈接數 } http { #http模塊,nginx核心模塊 include mime.types; #加載的多媒體資源類型配置文件 default_type application/octet-stream; #默認類型(16進制) sendfile on; #優化配置選項 keepalive_timeout 65; #長鏈接超時時間65秒 server { listen 80; #默認監聽的端口 server_name localhost; #網站域名 location / { #網站站點根目錄位置 root html; #網站文件 index index.html index.htm; #網站首頁 } error_page 500 502 503 504 /50x.html; #錯誤頁面500,502.503.504返回50x.html location = /50x.html { root html; } } }
1.5 啓動
/application/nginx/sbin/nginx –t #語法檢查並測試 /application/nginx/sbin/nginx #啓動 /application/nginx/sbin/nginx -s reload #平滑重啓,不影響用戶訪問 /application/nginx/sbin/nginx -s stop #關閉 /application/nginx/sbin/nginx -V #查看版本及安裝的模塊
啓動後會生成幾個temp目錄
瀏覽器訪問
編譯安裝Nginx完成
2.1下載並安裝相關編譯器
mkdir -p /service/tools #建立目錄 cd /service/tools/ wget http://mirrors.sohu.com/php/php-5.5.38.tar.gz #下載包 tar xf php-5.5.38.tar.gz #解壓 yum install gcc gcc-c++ glibc -y #安裝編譯器,若是已經編譯安裝了nginx則不須要此步驟 yum install -y libxml2-devel curl curl-devel libjpeg-devel libpng-devel freetype-devel 安裝編譯時所需庫 cd php-5.5.38 #進入php-5.5.38目錄
2.2 編譯安裝
編譯生成makefile
./configure --prefix=/application/php-5.5.38 --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64/ --with-curl --enable-fpm --enable-mbstring --with-gd --with-fpm-user=nginx --with-fpm-group=nginx make && make install
[root@Web02 php-5.5.38]# ln -s /application/php-5.5.38 /application/php #建立軟連接 [root@Web02 php-5.5.38]# ln -s /application/php/bin/* /usr/bin/ #建立命令軟連接 [root@Web02 php-5.5.38]# cp php.ini-production /application/php-5.5.38/etc/php.ini 拷貝默認配置文件 [root@Web02 php-5.5.38]# cp /application/php-5.5.38/etc/php-fpm.conf.default /application/php-5.5.38/etc/php-fpm.conf 拷貝默認php-fpm配置文件,php-fpm 啓動進程數
[root@Web02 php-5.5.38]# /application/php/sbin/php-fpm #啓動php [root@Web02 php-5.5.38]# netstat -lntup|grep 9000 #查看進程9000端口 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 97399/php-fpm
查看nginx.conf.default有關php的部分(65-71行),將此內容添加到nginx.conf中,並修改fastcgi_param指定script文件名documentrootdocumentrootfastcgi_script_name
能夠在/application/nginx/conf/fastcgi.conf查看
65 #location ~ \.php$ { 66 # root html; 67 # fastcgi_pass 127.0.0.1:9000; 68 # fastcgi_index index.php; 69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 70 # include fastcgi_params; 71 #} [root@Web02 php-5.5.38]# cd /application/nginx/conf/ [root@Web02 conf]# vim nginx.conf server { listen 80; server_name localhost; index index.php index.html index.htm; location / { root html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME documentrootdocumentrootfastcgi_script_name; include fastcgi_params; } } }
這個配置的意思是 在瀏覽器中訪問的.php文件,實際讀取的是 $document_root(網站根目錄)下的.php文件 -- 也就是說當訪問127.0.0.1/index.php的時候,須要讀取網站根目錄下面的index.php文件,若是沒有配置這一配置項時,nginx不回去網站根目錄下訪問.php文件,因此返回空白
配置項目中:include fastcgi_params; fastcgi_params 文件中含有各個nginx常量的定義,默認狀況 SCRIPT_FILENAME = /scripts$fastcgi_script_name
檢查語法nginx -t
[root@Web02 conf]# cd ../html/ #進入到站點目錄 [root@Web02 html]# ls 50x.html index.html [root@Web02 html]# rm -rf * #刪除原有的站點文件 [root@Web02 html]# wget http://static.kodcloud.com/update/download/kodexplorer4.37.zip
下載
[root@Web02 html]# unzip kodexplorer4.37.zip #解壓 [root@Web02 html]# nginx #啓動nginx
瀏覽器訪問
根據提示操做
su -c 'setenforce 0' #關閉selinux,su -c 指定命令,用root執行 chmod -R 777 /var/www/html/ #按照提示修改權限
刷新頁面從新訪問,成功,設置管理員用戶名和密碼,進行登陸及後續圖形界面操做