1. 程式人生 > >12.6 Nginx安裝

12.6 Nginx安裝

Nginx

12.6 Nginx安裝

大綱

技術分享圖片

技術分享圖片

1 進入src目錄,把nginx下載在此目錄

#cd /usr/local/src

#wget http://nginx.org/download/nginx-1.8.0.tar.gz

2 解壓壓縮包

#tar zxf nginx-1.12.1.tar.gz

3 進行編譯,安裝

#./configure --prefix=/usr/local/nginx

#make && make install

nginx的核心程序,也可以利用-t去檢查狀態。

[root@AliKvn usr]# ls /usr/local/nginx/sbin/nginx

/usr/local/nginx/sbin/nginx

[root@AliKvn usr]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

4 編輯nginx配置文件

#vim /etc/init.d/nginx //復制如下內容(參考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx )

技術分享圖片

5 更改文件755權限

#chmod 755 /etc/init.d/nginx

6 添加開機啟動服務

#chkconfig --add nginx

#chkconfig nginx on

7 配置Nginx的配置文件

#cd /usr/local/nginx/conf/

#mv nginx.conf nginx.conf.1

#vim nginx.conf //寫入如下內容(參考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf)

技術分享圖片

配置文件參數解析:

user 定義啟動Nginx指哪個用戶

worker_processes 2

啟動進程有2個子進程

worker_rlimit_nofile 51200 Nginx最多可以打開的文件數51200

use epoll; 使用epoll模式

worker_connections 6000 進程最多有6000個鏈接

server部分對應httpd的v-host虛擬主機

server_name 域名

location php 解析php相關參數部分

root 網頁路徑

技術分享圖片

一般監聽80端口出錯或者不通,大多數是跟server這部分配置參數有密切關系,

8 編輯完成後,檢查狀態,進程以及端口

[root@AliKvn conf]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

檢查無錯誤,嘗試啟動服務。

#/etc/init.d/nginx start

#ps aux |grep nginx 檢查進程,有2個子進程

Ss表示父進程,一般父進程user都是root,子進程都是nobody

截圖

檢查端口

#netstat -lntp |grep 80

測試頁面

#vim /usr/local/nginx/html/1.php

<?php

echo "this is the Nginx test page.";

curl檢查php解析測試

#curl localhost/1.php


12.6 Nginx安裝