安裝路徑: /usr/local/nginx
一、前期準備
(1)安裝依賴
yum install -y gcc gcc-c++ #編譯依賴
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel #nginx依賴
(2)下載nginx源碼包並解壓
cd download
wget https://nginx.org/download/nginx-1.14.0.tar.gz
tar -zxf nginx-1.14.0.tar.gz
(3)新建用戶nginx,以該用戶執行nginx
/bin/false 是最嚴格的禁止login選項,一切服務都不能用 /bin/nologin 只是不允許系統login,可以使用其他ftp等服務 如果想要用false在禁止login的同時允許ftp,則必須在/etc/shells裏增加一行/bin/false
二、編譯安裝
1. 生成makefile
/configure 可自行配置,具體查看官網說明 configure
cd nginx-1.14.0
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --with-pcre
2. 編譯安裝
make && make install
三、運行配置
1. 添加環境變量(軟鏈接)
ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
2. 配置php支持
編輯配置文件
vi /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME documentrootdocument_rootdocument
r
ootfastcgi_script_name;
include fastcgi_params;
}
四、命令
啓動nginx: nginx 停止nginx: nginx -s stop 重載nginx: nginx -s reload