nginx-1.12.0版本(編譯安裝)-自定義安裝路徑

nginx-1.12.0版本(編譯安裝)-自定義安裝路徑

安裝路徑:/application/nginx-1.12.0

1.前期準備

安裝編譯需要的gccgcc-c++

yum install -y gcc gcc-c++

nginx依賴

pcre-developenssl-develzlib-devel

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

創建用戶nginx,以該用戶的身份執行nginx

useradd -s /bin/false -M nginx

下載nginx源碼包並解壓到當前目錄

cd /tools
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxf nginx-1.12.0.tar.gz

 

2.nginx編譯安裝

生成Makefile文件

cd nginx-1.12.0
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.12.0/ --with-http_v2_module --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

編譯源代碼並安裝

make && make install

 

3.後期結尾

給nginx-1.12.0創建軟鏈接去掉末尾的版本號

ln -s /application/nginx-1.12.0/ /application/nginx

添加環境變量

創建nginx命令軟鏈接到環境變量

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

 

4.配置nginx開啓php支持

在server段中開啓php支持

cd /application/nginx
vim conf/nginx.conf


找到如下內容,刪除註釋字符,並將倒數第二行的 /scripts 替換爲 $document_root

修改前

#location ~ \.php$ {

#    root           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

修改後

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;

}

該段代碼在server中的位置:

server {

    listen       80;

    server_name  localhost;

    location / {

        root   html;

        index  index.php index.html index.htm;

    }

    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的值和location / {}塊中root的值需要一致

 

5.常用命令

檢查配置文件

nginx -t

指定其他配置文件啓動nginx

nginx -c /application/nginx/conf/nginx.conf.bak

啓動nginx

nginx

停止nginx

nginx -s stop

重啓nginx

nginx -s reload

參數解釋

-s stop 快速停止nginx

-s quit 平滑停止nginx

-s reopen 重新打開日誌文件

-s reload 平滑重載所有配置

 

6.目錄介紹

 [root@www nginx]# tree
.
├── conf  #配置文件目錄
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default  #fastcgi *配合php
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types  #mime 媒體類型
│   ├── mime.types.default
│   ├── nginx.conf  #nginx主配置文件
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html  #默認站點目錄
│   ├── 50x.html
│   └── index.html
├── logs  #訪問日誌、錯誤日誌、pid文件目錄
│   ├── access.log  #訪問日誌
│   ├── error.log  #錯誤日誌
│   └── nginx.pid  #pid文件
└── sbin  #命令目錄
└── nginx  #nginx命令文件


 


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